//
//  MinChart.m
//  Stock_Pro
//
//  Created by imuse on 10-11-21.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MinChart.h"

#import "Tools.h"
#import "DrawTools.h"
#import "ColorTools.h"
#import "ShowFormat.h"

#import "QuoteLvOper.h"
extern QUOTELV_OPER *g_pQuoteOper;

static NSString  *pCurVol;

@implementation MinChart
@synthesize isLandscape;

#define GAP_X 10
#define TITLE_HEIGHT 20      //成交量、总成交额处的高度
#define LEFT_WIDTH(a) (a? 5:3)       //框图左侧距离
#define RIGHT_WIDTH(b) (b? 5:3)        //框图右侧距离
#define MIN_POINT_MAX			272
#define LEFT_GAP_WIDTH 50

#define TOP_SPACING_PRICE   1
#define TOP_SPACING_VOLUME  TITLE_HEIGHT
#define TOP_SPACING_BS      TITLE_HEIGHT

#define TITLE_ITEM_SPACING  2

#define sal_color 0xFFFFFF
#define getColorRGB24(a,b) a>b?0xFF0000:a==b?0x0000000:0x00c800

- (instancetype)init
{
    return [self initWithFrame:CGRectZero withParent:nil];
}

- (id)initWithFrame:(CGRect)frame withParent:(id)parent {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    
    parentController = parent;
    
    pMinIndex = QuoteLvMinIndex_New();
    
    int nSize = sizeof(GUI_POINT)*MIN_POINT_MAX;
    //价格线
    pLineCur = (GUI_POINT*)Tools_Malloc(nSize);
    pLineAvg = (GUI_POINT*)Tools_Malloc(nSize);
    
    //成交量线
    pLineVol = (GUI_POINT*)Tools_Malloc(nSize);
    
    //红绿柱
    pRdpUp = (GUI_POINT*)Tools_Malloc(nSize);
    pRdpDown = (GUI_POINT*)Tools_Malloc(nSize);
    nRdpUp = nRdpDown = 0;
    
    //买卖力道
    pLineVolBuy = (GUI_POINT*)Tools_Malloc(nSize);
    pLineVolSell = (GUI_POINT*)Tools_Malloc(nSize);
    pVolBSBuy = (GUI_POINT*)Tools_Malloc(nSize);
    pVolBSSell = (GUI_POINT*)Tools_Malloc(nSize);
    nVolBuy = nVolSell = 0;
    
    //DDX
    //lisz add 20110916 start
    nSize = sizeof(GUI_RECT)*MIN_POINT_MAX;
    pLineDDXUp = Tools_Malloc(nSize);
    pLineDDXDown = Tools_Malloc(nSize);
    nSize = sizeof(GUI_POINT)*MIN_POINT_MAX;
    pDDX1 = Tools_Malloc(nSize);
    //  pDDX2 = Tools_Malloc(nSize);
    //  pDDX3 = Tools_Malloc(nSize);
    
    pFundFlow1 = Tools_Malloc(nSize);
    pFundFlow2 = Tools_Malloc(nSize);
    pFundFlow3 = Tools_Malloc(nSize);
    pFundFlow4 = Tools_Malloc(nSize);
    
    //bbd
    pBBD1 = Tools_Malloc(nSize);
    //lisz add 20110916 end
    
    
    //lisz add 20120810 start
    m_pf_point_x = Tools_Malloc(sizeof(float)*MIN_POINT_MAX);
    //lisz add 20120810 end
    
    
    //信息地雷
    pMine = (GUI_POINT*)Tools_Malloc(sizeof(GUI_POINT)*MIN_POINT_MAX);
    nMineCount = 0;
    //主题
    bgColor = [UIColor clearColor];
    priceColor = 0xFFFFFF;
    avgColor = 0xf6bb42;
    volColor = 0xffff00;
    tenLineColor = 0x6b6b6b;//0x656d78
    nVolScaleColor = 0xaaaaaa;
    //
    redColor = 0xee5050;
    greenColor = 0x44bb88;
    equalColor = 0xaaaaaa;
    bezierColor = 0x5d9cec;
    pathColor = 0x5d9cec;
    //
    frameColor = [HZCommonTool getThemeMinKlineSeprateColor];//0xdddddd
    scalesLineColor = [HZCommonTool getThemeMinKlineSeprateColor];//0xdddddd
    //
    self.backgroundColor = [UIColor clearColor];
    pMinRes = NULL;
    bMul = NO;
    nMaxPosCount = 242;
    
    nMode = MIN_SHOW_MODE_NORMAL;
    nExpandIndex =MIN_SHOW_INDEX_VOLUME;
    
    nPos = -1;
    isSeparatePriceLineAndVol = YES; //默认分开
  
    fPointR = 3;
  
    pLandScapeBtn = [UIButton new];
    [pLandScapeBtn addTarget:self action:@selector(landscapeBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    [pLandScapeBtn setImage:[UIImage imageNamed:@"landscape"] forState:UIControlStateNormal];
    [self addSubview:pLandScapeBtn];
    pLandScapeBtn.hidden = YES;
    
    //添加长按手势
    UILongPressGestureRecognizer *pLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressOnClick:)];
    [self addGestureRecognizer:pLongPress];
    
    //注册通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentVol:) name:kMinCurVolNotification object:nil];
    
    return self;
}

- (void)currentVol:(NSNotification *)noti
{
    pCurVol = noti.object;
}
- (void)longPressOnClick:(UILongPressGestureRecognizer *)press
{
    if (press.state == UIGestureRecognizerStateBegan) {
        if(!pMinRes){
            return;
        }
        bMul = YES;
        int x = [press locationInView:self].x;
        int w = self.frame.size.width-2 - LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape);
        nPos = (x-LEFT_WIDTH(isLandscape))*nMaxPosCount/w;
        if (nPos>=pMinRes->nTotalCount) {
            nPos=pMinRes->nTotalCount-1;
        }
        ty = pLineCur[nPos].y;
        [self OnChangeView:0];
        [self setNeedsDisplay];
    }else if (press.state == UIGestureRecognizerStateChanged) {
        if (bMul==NO) {
            return;
        }
        int x = [press locationInView:self].x;
        
        if (x == nLastPosX) {//禁止竖直滑动
            return;
        }
        nLastPosX = [press locationInView:self].x;
        
        int w = self.frame.size.width-2 - LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape);
        nPos = (x-LEFT_WIDTH(isLandscape))*nMaxPosCount/w;
        if (nPos>=pMinRes->nTotalCount) {
            nPos=pMinRes->nTotalCount-1;
        }
        ty = pLineCur[nPos].y;
        
        [self OnChangeView:0];
        [self setNeedsDisplay];
    }else if (press.state == UIGestureRecognizerStateEnded) {
        bMul = NO;
        [self setNeedsDisplay];
    }
}


- (void)landscapeBtnOnClick
{
    [self.parent upToParentWithObjc:self withType:kHZ_setLandscapeScreen_Action withParamter:nil];
}
- (void)setLandScapeBtnHidden:(BOOL)hidden
{
    pLandScapeBtn.hidden = hidden;
    isLandscape = hidden;
}

-(void) startTime
{
  nIndex = 0;
  if (pTimer) {
    [pTimer invalidate];
    pTimer = nil;
  }
  //启动定时器
  pTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(changeEvent:) userInfo:nil repeats:YES];
}

-(void) stopTime
{
  if (pTimer) {
    [pTimer invalidate];
    pTimer = nil;
  }
}

-(void) changeEvent:(NSTimer*)timer
{
  nIndex++;
  
//  CGContextRef g = UIGraphicsGetCurrentContext();
  
  if (nIndex % 2 == 0) {
    nIndex = 0;
  }
  
  if (nIndex == 1) {
    fPointR = 3.0;
  }else if(nIndex == 0){
    fPointR = 1.5;
  }
  
//  [self drawCircleWithContext:g];
  [self drawRect:self.frame];
}

-(void)setColors:(NSArray*)aArray
{
    
    if ([aArray count] >= 10) {
        bgColor = stringToHex([aArray objectAtIndex:0]);
        //self.backgroundColor = _rgb2uic(bgColor,1);
        priceColor = stringToHex([aArray objectAtIndex:1]);
        avgColor = stringToHex([aArray objectAtIndex:2]);
        volColor = stringToHex([aArray objectAtIndex:3]);
        tenLineColor = stringToHex([aArray objectAtIndex:4]);
        nVolScaleColor = tenLineColor;
        //
        redColor = stringToHex([aArray objectAtIndex:5]);
        greenColor = stringToHex([aArray objectAtIndex:6]);
        equalColor = stringToHex([aArray objectAtIndex:7]);
        frameColor = stringToHex([aArray objectAtIndex:8]);
        scalesLineColor = stringToHex([aArray objectAtIndex:9]);
    }
    
    [self setNeedsDisplay];
}

-(void)setMINIColor:(NSArray*)aArray
{
    if ([aArray count] >= 7) {
        bezierColor = stringToHex([aArray objectAtIndex:0]);
        pathColor = stringToHex([aArray objectAtIndex:1]);
        redColor = stringToHex([aArray objectAtIndex:2]);
        greenColor = stringToHex([aArray objectAtIndex:3]);
        equalColor = stringToHex([aArray objectAtIndex:4]);
        frameColor =stringToHex([aArray objectAtIndex:5]);
        scalesLineColor = stringToHex([aArray objectAtIndex:6]);
    }
}

-(int)getMinColor:(float)a with:(float)b
{
    if (a == b) {
        return 0x858585;
    }else if (a > b) {
        return 0xf60300;
    }else{
        return 0x30ae0e;
    }
}

-(void)setMode:(int)n
{
    nMode = n;
    switch (nMode) {
        case MIN_SHOW_MODE_NORMAL:
        {
            nExpandIndex = MIN_SHOW_INDEX_VOLUME;
            //
            mLeftView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
            //			[mLeftView setImage:[UIImage imageNamed:@"arrow_right.png"]];
            mLeftView.backgroundColor = [UIColor grayColor];
            mLeftView.layer.cornerRadius = 10;
            mLeftView.layer.masksToBounds = YES;
            mLeftView.hidden = YES;
            UILabel *left = [[UILabel alloc] initWithFrame:mLeftView.frame];
            left.textColor = [UIColor whiteColor];
            left.textAlignment = UITextAlignmentCenter;
            left.backgroundColor = [UIColor clearColor];
            left.font = [UIFont systemFontOfSize:9];
            [mLeftView addSubview:left];
            mLeft = left;
            
            mRightView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
            //			[mRightView setImage:[UIImage imageNamed:@"arrow_left.png"]];
            mRightView.backgroundColor = [UIColor grayColor];
            mRightView.layer.cornerRadius = 10;
            mRightView.layer.masksToBounds = YES;
            mRightView.hidden = YES;
            UILabel *right = [[UILabel alloc] initWithFrame:mRightView.frame];
            right.textColor = [UIColor whiteColor];
            right.textAlignment = UITextAlignmentCenter;
            right.backgroundColor = [UIColor clearColor];
            [mRightView addSubview:right];
            right.font = [UIFont systemFontOfSize:9];
            mRight = right;
            
            mBottomView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
            mBottomView.backgroundColor = [UIColor grayColor];
            mBottomView.layer.cornerRadius = 10;
            mBottomView.layer.masksToBounds = YES;
            mBottomView.hidden = YES;
            UILabel *bottom = [[UILabel alloc] initWithFrame:mBottomView.frame];
            bottom.textColor = [UIColor whiteColor];
            bottom.textAlignment = UITextAlignmentCenter;
            bottom.backgroundColor = [UIColor clearColor];
            bottom.font = [UIFont systemFontOfSize:9];
            [mBottomView addSubview:bottom];
            mBottom = bottom;
          
            CGRect rect = CGRectMake(LEFT_WIDTH(isLandscape), nPriceHeight + nPriceTop + 2, 70, TITLE_HEIGHT);
//            mVol = [[UILabel alloc] initWithFrame:rect];
//            mVol.textColor = _rgb2uic(equalColor, 1);
//            mVol.text = @"成交量";
//            mVol.font = [UIFont systemFontOfSize:9];
//            mVol.hidden = YES;
//            rect = CGRectMake(LEFT_WIDTH(isLandscape)+70, nPriceHeight + nPriceTop + 2, self.frame.size.width-70, TITLE_HEIGHT);
//            mVolValue = [[UILabel alloc] initWithFrame:rect];
//            mVolValue.textColor = _rgb2uic(equalColor, 1);
//            mVolValue.font = [UIFont systemFontOfSize:9];
//            mVolValue.hidden = YES;
          
            rect = CGRectMake(LEFT_WIDTH(isLandscape)+self.frame.size.width/2, nPriceHeight + nPriceTop + 2, 60, TITLE_HEIGHT);
            mHand = [[UILabel alloc] initWithFrame:rect];
            mHand.textColor = _rgb2uic(equalColor, 1);
            mHand.text = @"现手：";
            mHand.hidden = YES;
            mHand.font = [UIFont systemFontOfSize:9];
            rect = CGRectMake(LEFT_WIDTH(isLandscape)+self.frame.size.width/2+60, nPriceHeight + nPriceTop + 2, self.frame.size.width-60, TITLE_HEIGHT);
            mHandValue = [[UILabel alloc] initWithFrame:rect];
            mHandValue.textColor = _rgb2uic(equalColor, 1);
            mHandValue.font = [UIFont systemFontOfSize:9];
            mHand.hidden = YES;

            mVerButton = [UIButton buttonWithType:UIButtonTypeCustom];
            mVerButton.backgroundColor = _rgb2uic(0x2f5895, 1);
            [mVerButton setTitle:@"换横屏" forState:UIControlStateNormal];
            [mVerButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
            [mVerButton.layer setMasksToBounds:YES];
            [mVerButton.layer setCornerRadius:3.0]; //设置矩形四个圆角半径
            [mVerButton addTarget:self action:@selector(changeHorizontal:) forControlEvents:UIControlEventTouchUpInside];
          
            [self addSubview:mLeftView];
            [self addSubview:mRightView];
            [self addSubview:mBottomView];
//            [self addSubview:mVol];
//            [self addSubview:mVolValue];
//            [self addSubview:mHand];
//            [self addSubview:mHandValue];
//            [self addSubview:mVerButton];
        }
            break;
        case MIN_SHOW_MODE_EXPAND_INDEX:
            nExpandIndex = MIN_SHOW_INDEX_BUY_SELL_STRENGTH;
    }
}

-(void)setCurShowIndex:(int)n
{
    nExpandIndex = n;
    [self calcData];
    [self setNeedsDisplay];
}

- (void)updateNewData
{
    [self setData:&g_pQuoteOper->MinRes[0] withTradingHours:&g_pQuoteOper->tradeingHours];
}

-(void)setData:(QUOTELV_MIN_RES*)p withTradingHours:(QUOTELV_TRADING_HOURS*)pTradingHours
{
    [self clear];
    
    pMinRes = p;
    
    pItem = QuoteDataLv_GetTradingHoursItem(pTradingHours, pMinRes->codeinfo.market);
    int nTempMaxCount = nMaxPosCount;
    if (pItem) {
        nMaxPosCount = pItem->minuteCount;
    }
    else
    {
        if (pMinRes->codeinfo.style==STOCK_STYLE_FUTURES_STOCK) {
            nMaxPosCount = MIN_POINT_MAX;
        }
        else
        {
            nMaxPosCount = 242;
        }
    }
    
    if (nTempMaxCount < nMaxPosCount) {
        
        Tools_Free(&pLineCur);
        Tools_Free(&pLineAvg);
        Tools_Free(&pLineVol);
        Tools_Free(&pRdpUp);
        Tools_Free(&pRdpDown);
        Tools_Free(&pLineVolBuy);
        Tools_Free(&pLineVolSell);
        Tools_Free(&pVolBSBuy);
        Tools_Free(&pVolBSSell);
        //lisz add 20120810 start
        Tools_Free(&pDDX1);
        Tools_Free(&pLineDDXUp);
        Tools_Free(&pLineDDXDown);
        Tools_Free(&pFundFlow1);
        Tools_Free(&pFundFlow2);
        Tools_Free(&pFundFlow3);
        Tools_Free(&pFundFlow4);
        Tools_Free(&m_pf_point_x);
        //lisz add 20120810 end
        
        int nSize = sizeof(GUI_POINT)*nMaxPosCount;
        //价格线
        pLineCur = (GUI_POINT*)Tools_Malloc(nSize);
        pLineAvg = (GUI_POINT*)Tools_Malloc(nSize);
        
        //成交量线
        pLineVol = (GUI_POINT*)Tools_Malloc(nSize);
        
        //红绿柱
        pRdpUp = (GUI_POINT*)Tools_Malloc(nSize);
        pRdpDown = (GUI_POINT*)Tools_Malloc(nSize);
        nRdpUp = nRdpDown = 0;
        
        //买卖力道
        pLineVolBuy = (GUI_POINT*)Tools_Malloc(nSize);
        pLineVolSell = (GUI_POINT*)Tools_Malloc(nSize);
        pVolBSBuy = (GUI_POINT*)Tools_Malloc(nSize);
        pVolBSSell = (GUI_POINT*)Tools_Malloc(nSize);
        nVolBuy = nVolSell = 0;
        
        //lisz add 20120810 start
        //leve2
        pDDX1 = (GUI_POINT*)Tools_Malloc(nSize);
        pFundFlow1 = (GUI_POINT*)Tools_Malloc(nSize);
        pFundFlow2 = (GUI_POINT*)Tools_Malloc(nSize);
        pFundFlow3 = (GUI_POINT*)Tools_Malloc(nSize);
        pFundFlow4 = (GUI_POINT*)Tools_Malloc(nSize);
        
        nSize = sizeof(GUI_RECT)*nMaxPosCount;
        pLineDDXUp = Tools_Malloc(nSize);
        pLineDDXDown = Tools_Malloc(nSize);
        
        //bbd
        pBBD1 = Tools_Malloc(nSize);
        //分时x坐标
        m_pf_point_x = Tools_Malloc(sizeof(float)*MIN_POINT_MAX);
        //lisz add 20120810 end
    }
    
    
    [self OnChangeView:0];
}

-(QUOTELV_TRADING_HOURS_ITEM*)getTradingHours
{
    return pItem;
}

-(QUOTELV_STOCKINFO_RES*)getMineData
{
    return pMinInfoRes;
}

-(void)setMineData:(QUOTELV_STOCKINFO_RES*)p
{
    pMinInfoRes = p;
    [self calcMineData];
    [self setNeedsDisplay];
}

-(void)setVolData:(NSArray*)aData{
  if(aData.count == 2){
    mVolValue.text = aData[0];
    mHandValue.text = aData[1];
  }
}

-(void)calcMineData
{
    char sTime[16];
    int nTime;
    
    int nFirstLen;
    int nFBase;
    int nSBase;
    
    if (!pMinInfoRes || !pMinRes) {
        return;
    }
    
    if (pItem) {
        nFirstLen = CalcTimeDiffer(pItem->firstOpen, pItem->firstClose);
        nFBase = pItem->firstOpen;
        nSBase = pItem->secodeOpen;
    }
    else
    {
        if(pMinRes->codeinfo.style==STOCK_STYLE_FUTURES_STOCK)
        {
            nFBase = 915;
            nSBase = 1300;
            nFirstLen = 135;
        }
        else
        {
            nFBase = 930;
            nSBase = 1300;
            nFirstLen = 120;
        }
    }
    
    
    int w = self.frame.size.width-2 - LEFT_WIDTH(isLandscape);
    for (int i=0; i<pMinInfoRes->nTotalCount; i++)
    {
        memset(sTime,0,sizeof(sTime));
        //时
        memcpy(sTime, pMinInfoRes->infoData[i].pDate+8, 2);
        nTime = _a2i(sTime)*100;
        //分
        memcpy(sTime, pMinInfoRes->infoData[i].pDate+10, 2);
        nTime += _a2i(sTime);
        
        if (nTime>=nSBase) {
            nTime = nFirstLen+CalcTimeDiffer(nSBase, nTime);
        }
        else
        {
            if (nTime<nFBase) {
                //开市前
                nTime = 0;
            }
            else
            {
                nTime = CalcTimeDiffer(nFBase, nTime);
            }
        }
        
        
        //计算*显示信息，－3是为了让*号居中显示在分钟点上
        pMine[i].x = LEFT_WIDTH(isLandscape) + 1 + w*nTime/nMaxPosCount - 3;
        pMine[i].y = 2;
    }
    nMineCount = pMinInfoRes->nTotalCount;
}

-(void)clear
{
    pMinRes = NULL;
    pMinInfoRes = NULL;
    pItem = NULL;
    //	nPos = -1;
    [self setNeedsDisplay];
}

/*
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (bMul==NO) {
        return;
    }
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (!pMinRes) {
        return;
    }
//    if (!isLandscape) {
//        [self.parent upToSuperParentWithObjc:self andType:KMSMinChartViewType andOtherParamter:nil];
//    }else{
        if (!isMoved) {
            
            bMul = !bMul;
            if (bMul) {
                UITouch *t = [touches anyObject];
                int x = [t locationInView:self].x;
                
                int w = self.frame.size.width-2 - LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape);
                nPos = (x-LEFT_WIDTH(isLandscape))*nMaxPosCount/w;
                if (nPos>=pMinRes->nTotalCount) {
                    nPos=pMinRes->nTotalCount-1;
                }
                
                ty = pLineCur[nPos].y;
            }
            [self OnChangeView:0];
            [self setNeedsDisplay];
            
//            [self.parent upToSuperParentWithObjc:[NSNumber numberWithInt:nPos] andType:KMSMinClickIsShowTenLineActionType andOtherParamter:[NSNumber numberWithBool:bMul]];
        }
        
//    }
  
    isMoved = NO;
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesMoved:touches withEvent:event];
    
    if (!pMinRes) {
        return;
    }
    
    isMoved = YES;
    
    if (bMul==NO) {
        return;
    }
    UITouch *t = [touches anyObject];
    int x = [t locationInView:self].x;
    
    if (x == nLastPosX) {//禁止竖直滑动
        return;
    }
    nLastPosX = [t locationInView:self].x;
    
    
    int w = self.frame.size.width-2 - LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape);
    nPos = (x-LEFT_WIDTH(isLandscape))*nMaxPosCount/w;
    if (nPos>=pMinRes->nTotalCount) {
        nPos=pMinRes->nTotalCount-1;
    }
    ty = pLineCur[nPos].y;
    
    [self OnChangeView:0];
    [self setNeedsDisplay];
    
//    [self.parent upToSuperParentWithObjc:[NSNumber numberWithInt:nPos] andType:KMSMinClickIsShowTenLineActionType andOtherParamter:[NSNumber numberWithBool:bMul]];
}
*/
-(void)setPos:(int)n
{
    nPos = n;
    [self setNeedsDisplay];
}

-(int)getPos
{
    return nPos;
}

-(void)setMul:(BOOL)b
{
    bMul = b;
}

-(BOOL)getMulShow
{
    return bMul;
}

-(void)calcRect
{
    //单位高=(总高－时间刻度高)/5
    nItemHeight = (self.frame.size.height-2*TITLE_HEIGHT)/5;
    
    if (nMode==MIN_SHOW_MODE_MINI)
    {
        nPriceTop = TOP_SPACING_PRICE;
        nPriceHeight = self.frame.size.height-TOP_SPACING_PRICE - TITLE_HEIGHT;
    }
    else if(nMode==MIN_SHOW_MODE_NORMAL)
    {
        //价高=总高*3/5-价标题
        nPriceTop = TOP_SPACING_PRICE;//不包含标题TITLE_HEIGHT;
        nPriceHeight = nItemHeight*3;//不包含标题-TITLE_HEIGHT;
        
        //量高＝总高*1/5-量标题
        nVolTop = nPriceTop+nPriceHeight+TOP_SPACING_VOLUME;
        nVolHeight = nItemHeight*2;
        
        nVolExpandIndexTop = nVolTop;
        nVolExpandIndexHeight = nVolHeight;
    }
    else if(nMode==MIN_SHOW_MODE_EXPAND_INDEX)
    {
        //价高=总高*3/5-价标题
        nPriceTop = TOP_SPACING_PRICE;//不包含标题TITLE_HEIGHT;
        nPriceHeight = nItemHeight*3-TOP_SPACING_PRICE;//不包含标题-TITLE_HEIGHT;
        
        //量高＝总高*1/5-量标题
        nVolTop = nPriceTop+nPriceHeight+TOP_SPACING_VOLUME;
        nVolHeight = nItemHeight-TOP_SPACING_VOLUME;
        
        //买卖力道高=总高*1/5-量标题
        nVolExpandIndexTop = nVolTop+nVolHeight+TOP_SPACING_BS;
        nVolExpandIndexHeight = nItemHeight-TOP_SPACING_BS;
    }
  
    mVerButton.frame = CGRectMake(self.frame.size.width/2-30, nVolHeight + nVolTop + 2, 60, TITLE_HEIGHT);
    mVerButton.hidden = YES;
    if (!isLandscape) {
      mVerButton.hidden = NO;
        pLandScapeBtn.hidden = NO;
    }
    
    CGFloat fArrowY = nPriceTop+nPriceHeight + (TITLE_HEIGHT - 20)/2;
    pLandScapeBtn.frame = CGRectMake((self.frame.size.width - 20 - 10), fArrowY, 20, 20);
}

-(void)changeHorizontal:(id)sender{
//  if (!isLandscape) {
//          [self.parent upToSuperParentWithObjc:self andType:KMSMinChartViewType andOtherParamter:nil];
//      }
}

-(void)calcData
{
    //最大，小价，最大量
    float fMaxPrice;
    float fMinPrice;
    long64 lMaxVolume;
    
    //红绿柱最大最小
    int nMaxRdp;
    int nMinRdp;
    
    //买卖力道最大最小
    long64 lMaxBSVol;
    long64 lMinBSVol;
    long64 lMaxBSVolPM;	//最大正买卖力道差
    long64 lMaxBSVolNM;	//最大负买卖力道差
    
    //lisz add start 20120608
    int nCalcMaxPosCount;
    int nFirstPointCount;
    int nSecondPointCount;
    int fFirstWidth;
    int fSecondWidth;
    //lisz add end 20120608
    
    if (!pMinRes) {
        return;
    }
    
    if (pMinRes->nTotalCount>0)
    {
        //默认最大最小价
        fMaxPrice = pMinRes->minData[0].fPri;
        fMinPrice = pMinRes->minData[0].fPri;
        
        //成交量
        lMaxVolume = max(pMinRes->minData[0].lVol,3);
        
        //red green max and min
        nMaxRdp = pMinRes->minData[0].Rdp;
        nMinRdp = pMinRes->minData[0].Rdp;
        
        //最大，最小买卖量
        lMaxBSVol = max(pMinRes->minData[0].nTotalBuyVolume,pMinRes->minData[0].nTotalSellVolume);
        lMinBSVol = min(pMinRes->minData[0].nTotalBuyVolume,pMinRes->minData[0].nTotalSellVolume);
        lMaxBSVolNM = lMaxBSVolPM = pMinRes->minData[0].nTotalBuyVolume-pMinRes->minData[0].nTotalSellVolume;
        
    }
    else
    {
        //扩大1％
        fMaxPrice = pMinRes->fPre * 1.01;
        //减少1％
        fMinPrice = pMinRes->fPre * 0.99;
        lMaxVolume = 3;
        
        //red green max and min
        nMaxRdp = 0;
        nMinRdp = 0;
        
        //最大，最小买卖量
        lMaxBSVol = 0;
        lMinBSVol = 0;
        lMaxBSVolNM = 0;
    }
    
    if (lMaxBSVol==0) {
        lMaxBSVol=1;
        lMinBSVol=1;
        lMaxBSVolNM = lMaxBSVolPM = 0;
    }
    
    
    //imuse 20110225 high-speed get max and min number start
    int n = pMinRes->nTotalCount%2;
    n = pMinRes->nTotalCount-n;
    int ni;
    
    for(int i=0; i<n; i+=2)
    {
        ni=i+1;
        //get max and min price, speed 1.5*n
        if (pMinRes->minData[i].fPri>pMinRes->minData[ni].fPri) {
            fMaxPrice = max(fMaxPrice, pMinRes->minData[i].fPri);
            fMinPrice = min(fMinPrice, pMinRes->minData[ni].fPri);
        }
        else
        {
            fMaxPrice = max(fMaxPrice, pMinRes->minData[ni].fPri);
            fMinPrice = min(fMinPrice, pMinRes->minData[i].fPri);
        }
        
        //vol max or min, speed 2*n
        if (pMinRes->minData[i].lVol>pMinRes->minData[ni].lVol) {
            lMaxVolume = max(lMaxVolume, pMinRes->minData[i].lVol);
        }
        else
        {
            lMaxVolume = max(lMaxVolume, pMinRes->minData[ni].lVol);
        }
        
        
        //rdp max or min, speed 1.5*n
        if (pMinRes->minData[i].Rdp>pMinRes->minData[ni].Rdp) {
            nMaxRdp = max(nMaxRdp, pMinRes->minData[i].Rdp);
            nMinRdp = min(nMinRdp, pMinRes->minData[ni].Rdp);
        }
        else
        {
            nMaxRdp = max(nMaxRdp, pMinRes->minData[ni].Rdp);
            nMinRdp = min(nMinRdp, pMinRes->minData[i].Rdp);
        }
        
        //buy vol max or min, speed 1.5*n
        if (pMinRes->minData[i].nTotalBuyVolume>pMinRes->minData[ni].nTotalBuyVolume) {
            lMaxBSVol = max(lMaxBSVol, pMinRes->minData[i].nTotalBuyVolume);
            lMinBSVol = min(lMinBSVol, pMinRes->minData[ni].nTotalBuyVolume);
        }
        else {
            lMaxBSVol = max(lMaxBSVol, pMinRes->minData[ni].nTotalBuyVolume);
            lMinBSVol = min(lMinBSVol, pMinRes->minData[i].nTotalBuyVolume);
        }
        
        //sell vol max or min, speed 1.5*n
        if (pMinRes->minData[i].nTotalSellVolume>pMinRes->minData[ni].nTotalSellVolume) {
            lMaxBSVol = max(lMaxBSVol, pMinRes->minData[i].nTotalSellVolume);
            lMinBSVol = min(lMinBSVol, pMinRes->minData[ni].nTotalSellVolume);
        }
        else {
            lMaxBSVol = max(lMaxBSVol, pMinRes->minData[ni].nTotalSellVolume);
            lMinBSVol = min(lMinBSVol, pMinRes->minData[i].nTotalSellVolume);
        }
        
        
        lMaxBSVolPM = max(lMaxBSVolPM, (pMinRes->minData[i].nTotalBuyVolume-pMinRes->minData[i].nTotalSellVolume));
        lMaxBSVolNM = min(lMaxBSVolNM, (pMinRes->minData[i].nTotalBuyVolume-pMinRes->minData[i].nTotalSellVolume));
        
        lMaxBSVolPM = max(lMaxBSVolPM, (pMinRes->minData[ni].nTotalBuyVolume-pMinRes->minData[ni].nTotalSellVolume));
        lMaxBSVolNM = min(lMaxBSVolNM, (pMinRes->minData[ni].nTotalBuyVolume-pMinRes->minData[ni].nTotalSellVolume));
    }
    
    //过虑计算均价线
    if (n>0 && pMinRes->minData[0].fAvgPrice>0) {
        for(int i=0; i<n; i+=2){
            ni=i+1;
            //get max and min avg price, speed 1.5*n
            if (pMinRes->minData[i].fAvgPrice>pMinRes->minData[ni].fAvgPrice && pMinRes->minData[ni].fAvgPrice > 0){
                //增加容错后台返回的数据均价为0
                fMaxPrice = max(fMaxPrice, pMinRes->minData[i].fAvgPrice);
                fMinPrice = min(fMinPrice, pMinRes->minData[ni].fAvgPrice);
            }else{
                fMaxPrice = max(fMaxPrice, pMinRes->minData[ni].fAvgPrice);
                fMinPrice = min(fMinPrice, pMinRes->minData[i].fAvgPrice);
            }
        }
    }
    
    if (n<pMinRes->nTotalCount) {
        //过虑计算均价线
        if (pMinRes->minData[n].fAvgPrice>0) {
            if (pMinRes->minData[n].fPri>pMinRes->minData[n].fAvgPrice) {
                fMaxPrice = max(fMaxPrice, pMinRes->minData[n].fPri);
                fMinPrice = min(fMinPrice, pMinRes->minData[n].fAvgPrice);
            }else{
                fMaxPrice = max(fMaxPrice, pMinRes->minData[n].fAvgPrice);
                fMinPrice = min(fMinPrice, pMinRes->minData[n].fPri);
            }
        }else{
            fMaxPrice = max(fMaxPrice, pMinRes->minData[n].fPri);
            fMinPrice = min(fMinPrice, pMinRes->minData[n].fPri);
        }
        
        //成交量
        lMaxVolume = max(lMaxVolume, pMinRes->minData[n].lVol);
        
        //红绿柱
        nMaxRdp = max(nMaxRdp, pMinRes->minData[n].Rdp);
        nMinRdp = min(nMinRdp, pMinRes->minData[n].Rdp);
        
        //买卖力道
        if (pMinRes->minData[n].nTotalBuyVolume>pMinRes->minData[n].nTotalSellVolume)
        {
            lMaxBSVol = max(lMaxBSVol, pMinRes->minData[n].nTotalBuyVolume);
            lMinBSVol = min(lMinBSVol, pMinRes->minData[n].nTotalSellVolume);
        }else{
            lMaxBSVol = max(lMaxBSVol, pMinRes->minData[n].nTotalSellVolume);
            lMinBSVol = min(lMinBSVol, pMinRes->minData[n].nTotalBuyVolume);
        }
        
        lMaxBSVolPM = max(lMaxBSVolPM, (pMinRes->minData[n].nTotalBuyVolume-pMinRes->minData[n].nTotalSellVolume));
        lMaxBSVolNM = min(lMaxBSVolNM, (pMinRes->minData[n].nTotalBuyVolume-pMinRes->minData[n].nTotalSellVolume));
    }
    
    //ddx
    float fMaxDDX;
    float fMinDDX;
    
    //资金流向
    long64 lMaxFundFlow;
    long64 lMinFundFlow;
    
    //bbd
    long64 lMaxBBD;
    long64 lMinBBD;
    
    if (nExpandIndex==MIN_SHOW_INDEX_LEVE2_DDX) {
        //DDX
        QuoteLvMinIndex_calcDDX(pMinIndex, pMinRes);
        
        fMaxDDX = pMinIndex->DDX.ddx[0];
        fMaxDDX = max(fMaxDDX,pMinIndex->DDX.ddxSum[0]);
        
        fMinDDX = pMinIndex->DDX.ddx[0];
        fMinDDX = min(fMinDDX,pMinIndex->DDX.ddxSum[0]);
        
        for(int i=1; i<pMinRes->nLeve2TotalCount; i++)
        {
            //DDX
            fMaxDDX = max(fMaxDDX,pMinIndex->DDX.ddx[i]);
            fMaxDDX = max(fMaxDDX,pMinIndex->DDX.ddxSum[i]);
            
            fMinDDX = min(fMinDDX,pMinIndex->DDX.ddx[i]);
            fMinDDX = min(fMinDDX,pMinIndex->DDX.ddxSum[i]);
        }
        
        fScalesDDX[0] = fMaxDDX;
        fScalesDDX[1] = (fMaxDDX+fMinDDX)/2;
        fScalesDDX[2] = fMinDDX;
    } else if(nExpandIndex==MIN_SHOW_INDEX_LEVE2_FUND_FLOW) {
        //资金流向
        lMaxFundFlow = pMinRes->leve2MinData[0].lLittleAmountDiff;
        lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[0].lMidAmountDiff);
        lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[0].lBigAmountDiff);
        lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[0].lBiggerAmountDiff);
        
        
        lMinFundFlow = pMinRes->leve2MinData[0].lLittleAmountDiff;
        lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[0].lMidAmountDiff);
        lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[0].lBigAmountDiff);
        lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[0].lBiggerAmountDiff);
        
        for(int i=1; i<pMinRes->nLeve2TotalCount; i++)
        {
            lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[i].lLittleAmountDiff);
            lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[i].lMidAmountDiff);
            lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[i].lBigAmountDiff);
            lMaxFundFlow = max(lMaxFundFlow, pMinRes->leve2MinData[i].lBiggerAmountDiff);
            
            
            lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[i].lLittleAmountDiff);
            lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[i].lMidAmountDiff);
            lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[i].lBigAmountDiff);
            lMinFundFlow = min(lMinFundFlow, pMinRes->leve2MinData[i].lBiggerAmountDiff);
        }
        
        fScalesFundFlow[0] = lMaxFundFlow;
        fScalesFundFlow[1] = (lMaxFundFlow+lMinFundFlow)/2;
        fScalesFundFlow[2] = lMinFundFlow;
    } else if(nExpandIndex==MIN_SHOW_INDEX_LEVE2_BBD) {
        //BBD
        QuoteLvMinIndex_calcBBD(pMinIndex, pMinRes);
        lMaxBBD = pMinIndex->BBD.bbd[0];
        lMinBBD = pMinIndex->BBD.bbd[0];
        
        for(int i=1; i<pMinRes->nLeve2TotalCount; i++)
        {
            lMaxBBD = max(lMaxBBD, pMinIndex->BBD.bbd[i]);
            lMinBBD = min(lMinBBD, pMinIndex->BBD.bbd[i]);
        }
        
        fScalesBBD[0] = lMaxBBD;
        if (lMinBBD>0) {
            fScalesBBD[1] = lMaxBBD/2;
        } else if(lMaxBBD<0) {
            fScalesBBD[1] = lMinBBD/2;
        } else {
            fScalesBBD[1] = (lMaxBBD+lMinBBD)/2;
        }
        fScalesBBD[2] = lMinBBD;
    }
    
    //imuse 20110225 high-speed get max or min number end
    
    //没有开盘的股票
    if (fMaxPrice == fMinPrice && fMaxPrice == pMinRes->fPre) {
        //扩大1％
        fMaxPrice = pMinRes->fPre * 1.01;
        //减少1％
        fMinPrice = pMinRes->fPre * 0.99;
    }else if (absf(fMaxPrice - pMinRes->fPre)>=absf(fMinPrice - pMinRes->fPre))
    {
        fMinPrice = pMinRes->fPre - absf(fMaxPrice - pMinRes->fPre);
    }
    else
    {
        fMaxPrice = pMinRes->fPre + absf(fMinPrice - pMinRes->fPre);
    }
    
    if (abs(nMaxRdp)>abs(nMinRdp)) {
        nMinRdp = 0-nMaxRdp;
    }
    else
    {
        nMaxRdp = 0-nMinRdp;
    }
    
    
    //价刻度
    float MM = fMaxPrice - fMinPrice;
    for(int i=0; i<MIN_PRICE_SCALES_NUM; i++)
    {
        fScalesPrice[i] = fMaxPrice - MM*i/(MIN_PRICE_SCALES_NUM - 1);
    }
    
    //
    pMax = fMaxPrice;
    pMin = fMinPrice;
    
    fScalesPrice[2] = pMinRes->fPre;
    lScalesVolume[0] = lMaxVolume;
    lScalesVolume[1] = lMaxVolume/2;
    lScalesVolume[2] = 0;
    
    lScalesBS[0] = lMaxBSVol;
    lScalesBS[1] = lMaxBSVolNM;
    
    //幅度刻度
    for(int i=0; i<MIN_PRICE_SCALES_NUM; i++)
    {
        fScalesRange[i] = (fMaxPrice - MM*i/(MIN_PRICE_SCALES_NUM - 1) - pMinRes->fPre) / pMinRes->fPre * 100;
    }
    fScalesRange[2] = 0;
    //end
    
    int w;
    int nLeftWidth;
    
    nLeftWidth = LEFT_WIDTH(isLandscape);
    
    //计算区域
    [self calcRect];
    
    if (nMode == MIN_SHOW_MODE_MINI) {
        w = self.frame.size.width - nLeftWidth - 2;
    }else {
        w = self.frame.size.width - nLeftWidth - RIGHT_WIDTH(isLandscape) - 2;
    }
    
    //lisz add start 20120608
    nCalcMaxPosCount = (nMaxPosCount-1);
    //lisz add end 20120608
    
    
    //	h = nPriceHeight-2;
    
    int x0,y0,x1;
    int np = 0;
    float fMax,fSM;
    fMax = fMaxPrice;
    
    int nRdpH;
    int nRdpU;
    int nRdpD;
    int nRdpY;
    nRdpH = nPriceHeight/4;
    nRdpU = nRdpD = 0;
    nRdpY = nPriceTop+nPriceHeight/2;
    
    //	int BSMM;
    //	BSMM = lMaxVol-lMinVol;
    
    
    /*清空原价，均价，红绿柱，买卖力道，点坐标*/
    memset(pLineCur, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pLineAvg, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pLineVol, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pRdpUp, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pRdpDown, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pLineVolBuy, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pLineVolSell, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pVolBSBuy, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pVolBSSell, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pDDX1, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pLineDDXUp, 0, sizeof(GUI_RECT)*nMaxPosCount);
    memset(pLineDDXDown, 0, sizeof(GUI_RECT)*nMaxPosCount);
    memset(pFundFlow1, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pFundFlow2, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pFundFlow3, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pFundFlow4, 0, sizeof(GUI_POINT)*nMaxPosCount);
    memset(pBBD1, 0, sizeof(GUI_POINT)*nMaxPosCount);
    
    nVolBuy = nVolSell = 0;
    
    long64 lMaxBS;
    long64 lMaxBSSH;
    lMaxBS = lMaxBSVol;
    lMaxBSSH = 0;
    if(lMaxBSVolNM<0)
    {
        lMaxBS += (-lMaxBSVolNM);
        lMaxBSSH = (-lMaxBSVolNM);
    }
    if (!pItem) {
        return;
    }
    nFirstPointCount = CalcTimeDiffer(pItem->firstOpen, pItem->firstClose)+1;
    nSecondPointCount = CalcTimeDiffer(pItem->secodeOpen, pItem->secodeClose)+1;
    fFirstWidth = (w)*1.0/(nFirstPointCount+nSecondPointCount)*nFirstPointCount;
    fSecondWidth = (w)*1.0/(nFirstPointCount+nSecondPointCount)*nSecondPointCount;
    
    for (int i=0; i<(nFirstPointCount+nSecondPointCount); i++) {
        if (i<nFirstPointCount) {
            m_pf_point_x[i] = nLeftWidth + 1 +
            (fFirstWidth*(float)i)/(nFirstPointCount-1);
        } else {
            m_pf_point_x[i] = nLeftWidth + 1 + fFirstWidth +
            (fSecondWidth*(float)(i-nFirstPointCount+1))/(nSecondPointCount);
        }
    }
    
    
    for(int i=0; i<pMinRes->nTotalCount; i++)
    {
        x0 = m_pf_point_x[i];//nLeftWidth + 1 + w*i/nMaxPosCount;
        
        pLineCur[np].x = x0;
        pLineAvg[np].x = x0;
        fSM = fMax - pMinRes->minData[i].fPri;
        fSM = fSM*nPriceHeight/MM;
        //价
        y0 = nPriceTop + 0 + fSM;//nPriceTop + 1 + fSM;
        pLineCur[np].y = y0;
        fSM = fMax - pMinRes->minData[i].fAvgPrice;
        fSM = fSM*nPriceHeight/MM;
        //均价
        if (pMinRes->minData[i].fAvgPrice > 0/* && pMinRes->minData[i+1].fAvgPrice > 0 */)
        {
            y0 = nPriceTop + 0 + fSM;//nPriceTop + 1 +  fSM;
            pLineAvg[np].y = y0;
        }
        //okex，并且最大红绿柱不为0
        if (pMinRes->codeinfo.style==STOCK_STYLE_INDEX && nMaxRdp!=0) {
            //rdp
            if (pMinRes->minData[i].Rdp>0) {
                pRdpUp[nRdpU].x = x0;
                pRdpUp[nRdpU].y = nRdpY - 1 - (pMinRes->minData[i].Rdp)*nRdpH/nMaxRdp;
                nRdpU++;
            }
            else{
                pRdpDown[nRdpD].x = x0;
                pRdpDown[nRdpD].y = nRdpY + 1 - (pMinRes->minData[i].Rdp)*nRdpH/nMaxRdp;
                nRdpD++;
            }
        }
        np++;
    }
    
    //因买卖力道可能是0,为了提高执行效率不在计算价格时同步计算买卖力道而是单独处理买卖力道,
    if (lMaxBS!=0)
    {
        np = 0;
        nBS0Y = nVolExpandIndexTop + 1 + (lMaxBS-lMaxBSSH)*nVolExpandIndexHeight/lMaxBS;
        for(int i=0; i<pMinRes->nTotalCount; i++)
        {
            x0 = m_pf_point_x[i];//nLeftWidth + 1 + w*i/nMaxPosCount;
            
            //买卖力道
            pLineVolBuy[np].x = x0;
            pLineVolSell[np].x = x0;
            
            //开盘时买卖力道可能是0
            pLineVolBuy[np].y = nVolExpandIndexTop + (lMaxBS-pMinRes->minData[i].nTotalBuyVolume-lMaxBSSH)*nVolExpandIndexHeight/lMaxBS;
            pLineVolSell[np].y = nVolExpandIndexTop + (lMaxBS-pMinRes->minData[i].nTotalSellVolume-lMaxBSSH)*nVolExpandIndexHeight/lMaxBS;
            if (pMinRes->minData[i].nTotalBuyVolume>=pMinRes->minData[i].nTotalSellVolume) {
                //正的
                pVolBSBuy[nVolBuy].x = x0;
                pVolBSBuy[nVolBuy].y = nVolExpandIndexTop + 1 + (lMaxBS-(pMinRes->minData[i].nTotalBuyVolume-pMinRes->minData[i].nTotalSellVolume+lMaxBSSH))*nVolExpandIndexHeight/lMaxBS;
                nVolBuy++;
            }
            else
            {
                //负的
                pVolBSSell[nVolSell].x = x0;
                pVolBSSell[nVolSell].y = nVolExpandIndexTop + 1 + (lMaxBS-(lMaxBSSH-(pMinRes->minData[i].nTotalSellVolume-pMinRes->minData[i].nTotalBuyVolume)))*nVolExpandIndexHeight/lMaxBS;
                nVolSell++;
            }
            
            np++;
        }
    }
    
    
    nRdpUp = nRdpU;
    nRdpDown = nRdpD;
    
    {
        long64 lTemp;
        
        for(int i=0; i<pMinRes->nTotalCount; i++)
        {
            x1 = x0 = m_pf_point_x[i];//nLeftWidth + 1 + w*i/nMaxPosCount;
            pLineVol[i].x = x0;
            //量
            lTemp = (lMaxVolume - pMinRes->minData[i+1].lVol)*nVolHeight/lMaxVolume;
            pLineVol[i].y = nVolTop + 1 + (int)lTemp;
        }
    }
    
    if (nExpandIndex==MIN_SHOW_INDEX_LEVE2_DDX) {
        //ddx
        float MMDDX;
        MMDDX = nVolExpandIndexHeight/(fMaxDDX-fMinDDX);
        
        
        float MMDD;
        MMDD = absf(fMaxDDX)+absf(fMinDDX);
        
        nDDX_Y_0 = nVolExpandIndexTop + (MMDD-absf(fMinDDX))/MMDD*nVolExpandIndexHeight;
        
        int nDDUp,nDDDown;
        nDDUp = nDDDown = 0;
        
        for(int i=0; i<pMinRes->nLeve2TotalCount; i++)
        {
            x1 = x0 = m_pf_point_x[i];//nLeftWidth + 1 + w*i/nMaxPosCount;
            //DDX
            pDDX1[i].x = x1;
            pDDX1[i].y = nVolExpandIndexTop + (fMaxDDX - pMinIndex->DDX.ddxSum[i])*MMDDX;
            
            
            if(pMinIndex->DDX.ddx[i]>0)
            {
                pLineDDXUp[nDDUp].nLeft = x1;
                pLineDDXUp[nDDUp].nRight = x1+1;
                pLineDDXUp[nDDUp].nTop = nVolExpandIndexTop + (MMDD-(pMinIndex->DDX.ddx[i]+absf(fMinDDX)))*MMDDX;
                pLineDDXUp[nDDUp].nBottom = nDDX_Y_0;
                if (pLineDDXUp[nDDUp].nTop == pLineDDXUp[nDDUp].nBottom) {
                    pLineDDXUp[nDDUp].nTop--;
                }
                nDDUp++;
            }
            else
            {
                pLineDDXDown[nDDDown].nLeft = x1;
                pLineDDXDown[nDDDown].nRight = x1+1;
                pLineDDXDown[nDDDown].nTop = nDDX_Y_0;
                pLineDDXDown[nDDDown].nBottom = nVolExpandIndexTop + (MMDD-(absf(fMinDDX)-absf(pMinIndex->DDX.ddx[i])))*MMDDX;
                if (pLineDDXDown[nDDDown].nTop == pLineDDXDown[nDDDown].nBottom) {
                    pLineDDXDown[nDDDown].nBottom++;
                }
                nDDDown++;
            }
            
            np++;
        }
        if (pLineDDXUp[0].nTop == -1 && pLineDDXUp[0].nBottom == 0) {//add by jason 数据为0时，特殊处理
            nDDX_DDUpLen = 0;
        }else {
            nDDX_DDUpLen = nDDUp;
        }
        if (pLineDDXDown[0].nTop == 0 && pLineDDXDown[0].nBottom == 1) {//add by jason 数据为0时，特殊处理
            nDDX_DDDownLen = 0;
        }else {
            nDDX_DDDownLen = nDDDown;
        }
        
    } else if(nExpandIndex==MIN_SHOW_INDEX_LEVE2_FUND_FLOW) {
        //资金流向
        long64 MMDD;
        MMDD = absf(lMaxFundFlow)+absf(lMinFundFlow);
        
        double MMDDX;
        MMDDX = (nVolExpandIndexHeight+0.0)/MMDD;
        
        //nDDX_Y_0 = nVolExpandIndexTop + (MMDD-absf(fMinDDX))*MMDDX;
        //nDDX_Y_0 = nVolExpandIndexTop + (MMDD-absf(fMinDDX))/MMDD*nVolExpandIndexHeight;
        
        for(int i=0; i<pMinRes->nLeve2TotalCount; i++)
        {
            x1 = x0 = m_pf_point_x[i];//nLeftWidth + 1 + w*i/nMaxPosCount;
            //DDX
            pFundFlow1[i].x = pFundFlow2[i].x = pFundFlow3[i].x = pFundFlow4[i].x = x1;
            pFundFlow1[i].y = nVolExpandIndexTop + (lMaxFundFlow-pMinRes->leve2MinData[i].lLittleAmountDiff)*MMDDX;
            pFundFlow2[i].y = nVolExpandIndexTop + (lMaxFundFlow-pMinRes->leve2MinData[i].lMidAmountDiff)*MMDDX;
            pFundFlow3[i].y = nVolExpandIndexTop + (lMaxFundFlow-pMinRes->leve2MinData[i].lBigAmountDiff)*MMDDX;
            pFundFlow4[i].y = nVolExpandIndexTop + (lMaxFundFlow-pMinRes->leve2MinData[i].lBiggerAmountDiff)*MMDDX;
        }
    } else if(nExpandIndex==MIN_SHOW_INDEX_LEVE2_BBD) {
        //大单净额差累积
        long64 MMDD;
        
        if (lMinBBD>0) {
            MMDD = lMaxBBD;
        } else if(lMaxBBD<0) {
            MMDD = abs(lMinBBD);
        } else {
            MMDD = absf(lMaxBBD)+absf(lMinBBD);
        }
        
        //MMDD = absf(lMaxBBD)+absf(lMaxBBD);
        
        double MMDDX;
        MMDDX = (nVolExpandIndexHeight+0.0)/MMDD;
        
        for(int i=0; i<pMinRes->nLeve2TotalCount; i++)
        {
            x1 = x0 = m_pf_point_x[i];//nLeftWidth + 1 + w*i/nMaxPosCount;
            //DDX
            pBBD1[i].x = x1;
            pBBD1[i].y = nVolExpandIndexTop + (lMaxBBD-pMinIndex->BBD.bbd[i])*MMDDX;
        }
    }
}


//lisz add 20110916 start

//绘圆
- (void)drawCircleWithContext:(CGContextRef)context
{
    if(context == 0x0){
      return;
    }
    if (!context || !pMinRes || pMinRes->nTotalCount == nMaxPosCount) {
        return;
    }
    
    GUI_POINT nLastPoint = pLineCur[pMinRes->nTotalCount - 1];
    CGContextAddArc(context, nLastPoint.x, nLastPoint.y, fPointR, 0, 2*M_PI, 0);
    CGContextSetRGBFillColor(context, 93/255.f, 157/255.f, 236/255.f, 0.5);
    CGContextDrawPath(context, kCGPathFill);
    
    CGContextAddArc(context, nLastPoint.x, nLastPoint.y, 1.5, 0, 2*M_PI, 0);
    CGContextSetRGBFillColor(context, 93/255.f, 157/255.f, 236/255.f, 1);
    CGContextDrawPath(context, kCGPathFill);
}

///成交量
- (void)drawVolume:(CGContextRef)g
{
    //成交量
    int nColor = 0;
    for (int i=0; i<pMinRes->nTotalCount; i++) {
        nColor = [self getMinColor:pMinRes->minData[i].fPri with: pMinRes->minData[i-1].fPri];
        DrawTools_DrawNewLine(g, pLineVol[i].x, pLineVol[i].y, pLineVol[i].x, nVolTop+nVolHeight+1, nColor, 0, 1);
    }
    //成交量刻度
    char sTemp[64];
    GUI_RECT rText;
    rText.nLeft = 10;
    rText.nRight = rText.nLeft+LEFT_GAP_WIDTH;
    
    //左侧刻度
    GUI_RECT rTextRight;
    rTextRight.nLeft = self.frame.size.width - RIGHT_WIDTH(isLandscape);
    rTextRight.nRight = rTextRight.nLeft+RIGHT_WIDTH(isLandscape);
    
    rText.nTop = nVolTop-TITLE_HEIGHT/2 + 10;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    sprintf(sTemp, "%lld", lScalesVolume[0]);
    DrawTools_DrawText(g, &rText, sTemp, nVolScaleColor, AGIN_LEFT);
    
    rText.nTop = nVolTop+(nVolHeight)/2;
    rText.nBottom = rText.nTop+20;
    sprintf(sTemp, "%lld", lScalesVolume[1]);
    DrawTools_DrawText(g, &rText, sTemp, nVolScaleColor, AGIN_LEFT);
    //成交量标题
      rText.nTop = nVolTop-TITLE_HEIGHT;
      rText.nBottom = rText.nTop+TITLE_HEIGHT;
      rText.nLeft = RIGHT_WIDTH(isLandscape);
      rText.nRight = self.frame.size.width-2;
      NSString *s = [NSString stringWithFormat:@"成交量:%@",VolSumShow(pMinRes->lTotalVol)];
      DrawTools_DrawNSText(g, &rText, (__bridge void *)(s), nVolScaleColor/*sal_color*/, AGIN_LEFT);

      rText.nLeft += 95;
    if (!pCurVol) {
        pCurVol = @"-";
    }
      s = [NSString stringWithFormat:@"现手:%@", pCurVol];
      DrawTools_DrawNSText(g, &rText, (__bridge void *)s, nVolScaleColor/*sal_color*/, AGIN_LEFT);
}

///买卖力道
- (void)drawBuySellStrength:(CGContextRef)g withPos:(int)nIndex
{
    for (int i=0; i<nVolBuy; i++) {
        DrawTools_DrawLine(g, pVolBSBuy[i].x, pVolBSBuy[i].y, pVolBSBuy[i].x, nBS0Y, 0xFF0000, 0);
    }
    for (int i=0; i<nVolSell; i++) {
        DrawTools_DrawLine(g, pVolBSSell[i].x, pVolBSSell[i].y, pVolBSSell[i].x, nBS0Y, 0x22FF22, 0);
    }
    
    DrawTools_DrawPath(g, pLineVolBuy, pMinRes->nTotalCount, /*0xFFFFFF*/priceColor);
    DrawTools_DrawPath(g, pLineVolSell, pMinRes->nTotalCount, /*0xFFFF00*/avgColor);
    
    NSString *s;
    char sTemp[64];
    GUI_RECT rText;
    rText.nLeft = 0;
    rText.nRight = rText.nLeft+LEFT_WIDTH(isLandscape);
    
    //买卖力道刻度
    rText.nLeft = 0;
    rText.nRight = LEFT_WIDTH(isLandscape);
    rText.nTop = nVolExpandIndexTop-10;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    //右侧刻度
    GUI_RECT rTextRight;
    rTextRight.nLeft = self.frame.size.width - RIGHT_WIDTH(isLandscape);
    rTextRight.nRight = rTextRight.nLeft+RIGHT_WIDTH(isLandscape);
    
    sprintf(sTemp, "%lld", lScalesBS[0]);
    DrawTools_DrawText(g, &rText, sTemp, /*0x00AAFF*/nVolScaleColor, AGIN_RIGHT);
    rTextRight.nTop = rText.nTop;
    rTextRight.nBottom = rText.nBottom;
    DrawTools_DrawText(g, &rTextRight, sTemp, nVolScaleColor, AGIN_LEFT);
    
    rText.nTop = nVolExpandIndexTop+(nVolExpandIndexHeight)-10;
    rText.nBottom = rText.nTop+14;
    sprintf(sTemp, "%lld", lScalesBS[1]);
    DrawTools_DrawText(g, &rText, sTemp, /*0x00AAFF*/nVolScaleColor, AGIN_RIGHT);
    rTextRight.nTop = rText.nTop;
    rTextRight.nBottom = rText.nBottom;
    DrawTools_DrawText(g, &rTextRight, sTemp, nVolScaleColor, AGIN_LEFT);
    
    float fontSize = 10.0;
    UIFont *pFont = [UIFont systemFontOfSize:fontSize];
    
    //买卖力道
    rText.nTop = nVolExpandIndexTop-TITLE_HEIGHT;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    rText.nLeft = LEFT_WIDTH(isLandscape)+1;
    
    s = [NSString stringWithFormat:@"委买:%@",VolSumShow(pMinRes->minData[nIndex].nTotalBuyVolume)];
    CGSize charSize = [s sizeWithFont:pFont];
    rText.nRight = rText.nLeft+charSize.width;
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(s), /*0xFFFFFF*/priceColor, AGIN_LEFT, fontSize);
    
    //NSLog(s);
    
    
    rText.nLeft = rText.nRight+TITLE_ITEM_SPACING;
    //rText.nRight = rText.nLeft+80;
    s = [NSString stringWithFormat:@"委卖:%@",VolSumShow(pMinRes->minData[nIndex].nTotalSellVolume)];
    charSize = [s sizeWithFont:pFont];
    rText.nRight = rText.nLeft+charSize.width;
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(s), /*0xFFFF00*/avgColor, AGIN_LEFT, fontSize);
    
    rText.nLeft = rText.nRight+TITLE_ITEM_SPACING;
    //rText.nRight = rText.nLeft+80;
    long64 ll;
    ll = pMinRes->minData[nIndex].nTotalBuyVolume - pMinRes->minData[nIndex].nTotalSellVolume;
    s = [NSString stringWithFormat:@"委差:%@",VolSumShow(ll)];
    //s = [NSString stringWithFormat:@"委差:%@",VolSumShow(pMinRes->minData[nIndex].nTotalBuyVolume-pMinRes->minData[nIndex].nTotalSellVolume)];
    charSize = [s sizeWithFont:pFont];
    rText.nRight = rText.nLeft+charSize.width;
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(s), getColorRGB24(pMinRes->minData[nIndex].nTotalBuyVolume,pMinRes->minData[nIndex].nTotalSellVolume), AGIN_LEFT, fontSize);
    
    rText.nLeft = rText.nRight+TITLE_ITEM_SPACING;
    //rText.nRight = rText.nLeft+80;
    float f;
    if (pMinRes->minData[nIndex].nTotalBuyVolume>0&&pMinRes->minData[nIndex].nTotalSellVolume>0)
    {
        f = (pMinRes->minData[nIndex].nTotalBuyVolume+0.0)/pMinRes->minData[nIndex].nTotalSellVolume;
        s = [NSString stringWithFormat:@"多空比:%.2f",f];
    }
    else
    {
        f = (pMinRes->minData[nIndex].nTotalBuyVolume+0.0)/pMinRes->minData[nIndex].nTotalSellVolume;
        s = [NSString stringWithFormat:@"多空比:-"];
    }
    charSize = [s sizeWithFont:pFont];
    rText.nRight = rText.nLeft+charSize.width;
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(s), getColorRGB24(pMinRes->minData[nIndex].nTotalBuyVolume,pMinRes->minData[nIndex].nTotalSellVolume), AGIN_LEFT, fontSize);
}
///绘leve2 ddx
- (void)drawLeve2DDX:(CGContextRef)g
{
    GUI_RECT rText;
    int nPosT;
    
    
    DrawTools_DrawLine(g, LEFT_WIDTH(isLandscape), nDDX_Y_0, self.frame.size.width, nDDX_Y_0, 0x676767, PEN_STYLE_DOTLINE);
    DrawTools_FullRectArr(g, pLineDDXUp, nDDX_DDUpLen, 0xFF0000);
    DrawTools_FullRectArr(g, pLineDDXDown, nDDX_DDDownLen, 0x00FFFF);
    
    DrawTools_DrawPath(g, pDDX1, pMinRes->nLeve2TotalCount, 0xFFFF00);
    //  DrawTools_DrawPath(g, pDDX2, pMinRes->nLeve2TotalCount, 0xFF00FF);
    //  DrawTools_DrawPath(g, pDDX3, pMinRes->nLeve2TotalCount, 0x00FF00);
    
    rText.nLeft = 0;
    rText.nRight = LEFT_WIDTH(isLandscape);
    rText.nTop = nVolExpandIndexTop-10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[0]]), 0x00AAFF, AGIN_RIGHT);
    
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight/2 - 10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[1]]), 0x00AAFF, AGIN_RIGHT);
    
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight-10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesDDX[2]]), 0x00AAFF, AGIN_RIGHT);
    
    nPosT = nPos;
    if (nPosT < 0 || nPosT>=pMinRes->nLeve2TotalCount) {
        nPosT=pMinRes->nLeve2TotalCount-1;
    }
    
    //绘量标题
    rText.nLeft = LEFT_WIDTH(isLandscape);
    rText.nRight = self.frame.size.width;
    rText.nTop = nVolExpandIndexTop-TITLE_HEIGHT;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    NSString *pStr;
    float fontSize = 10.0;
    UIFont *pFont = [UIFont systemFontOfSize:fontSize];
    
    pStr = [NSString stringWithFormat:@"DDX:%.3f", pMinIndex->DDX.ddx[nPosT]];
    CGSize charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+5;
    pStr = [NSString stringWithFormat:@"DDX累积:%.3f", pMinIndex->DDX.ddxSum[nPosT]];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
}

- (void)drawLeve2FundFlow:(CGContextRef)g
{
    DrawTools_DrawPath(g, pFundFlow1, pMinRes->nLeve2TotalCount, 0x00FF00);
    DrawTools_DrawPath(g, pFundFlow2, pMinRes->nLeve2TotalCount, 0xFFFF00);
    DrawTools_DrawPath(g, pFundFlow3, pMinRes->nLeve2TotalCount, 0xFF0000);
    DrawTools_DrawPath(g, pFundFlow4, pMinRes->nLeve2TotalCount, 0xFFFFFF);
    
    //int nHight;
    GUI_RECT rText;
    
    //nHight = self.frame.size.height/3;
    rText.nLeft = 0;
    rText.nRight = LEFT_WIDTH(isLandscape);
    rText.nTop = nVolExpandIndexTop-10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesFundFlow[0]]), 0x00AAFF, AGIN_RIGHT);
    
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight/2 - 10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesFundFlow[1]]), 0x00AAFF, AGIN_RIGHT);
    
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight-10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)([NSString stringWithFormat:@"%.2f", fScalesFundFlow[2]]), 0x00AAFF, AGIN_RIGHT);
    
    int nPosT;
    nPosT = nPos;
    if (nPosT < 0 || nPosT>=pMinRes->nLeve2TotalCount) {
        nPosT=pMinRes->nLeve2TotalCount-1;
    }
    //绘量标题
    rText.nLeft = LEFT_WIDTH(isLandscape);
    rText.nRight = self.frame.size.width;
    rText.nTop = nVolExpandIndexTop-TITLE_HEIGHT;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    NSString *pStr;
    float fontSize = 10.0;
    UIFont *pFont = [UIFont systemFontOfSize:fontSize];
    
    pStr = [NSString stringWithFormat:@"散:%@",  VolSumShow(pMinRes->leve2MinData[nPosT].lLittleAmountDiff)];
    CGSize charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0x00FF00, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+TITLE_ITEM_SPACING;
    pStr = [NSString stringWithFormat:@"中:%@", VolSumShow(pMinRes->leve2MinData[nPosT].lMidAmountDiff)];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+TITLE_ITEM_SPACING;
    pStr = [NSString stringWithFormat:@"大:%@", VolSumShow(pMinRes->leve2MinData[nPosT].lBigAmountDiff)];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFF0000, AGIN_LEFT,fontSize);
    rText.nLeft = rText.nLeft+charSize.width+TITLE_ITEM_SPACING;
    pStr = [NSString stringWithFormat:@"特大:%@", VolSumShow(pMinRes->leve2MinData[nPosT].lBiggerAmountDiff)];
    charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFFFF, AGIN_LEFT,fontSize);
}

- (void)drawLeve2BBD:(CGContextRef)g
{
    DrawTools_DrawPath(g, pBBD1, pMinRes->nLeve2TotalCount, 0xFFFFFF);
    
    GUI_RECT rText;
    
    rText.nLeft = 0;
    rText.nRight = LEFT_WIDTH(isLandscape);
    rText.nTop = nVolExpandIndexTop-10;
    rText.nBottom = rText.nTop+20;
    
    DrawTools_DrawNSText(g, &rText, (__bridge void *)(VolSumShow(fScalesBBD[0])), 0x00AAFF, AGIN_RIGHT);
    
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight/2 - 10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)(VolSumShow(fScalesBBD[1])), 0x00AAFF, AGIN_RIGHT);
    
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight-10;
    rText.nBottom = rText.nTop+20;
    DrawTools_DrawNSText(g, &rText, (__bridge void *)(VolSumShow(fScalesBBD[2])), 0x00AAFF, AGIN_RIGHT);
    
    int nPosT;
    nPosT = nPos;
    if (nPosT < 0 || nPosT>=pMinRes->nLeve2TotalCount) {
        nPosT=pMinRes->nLeve2TotalCount-1;
    }
    //绘量标题
    rText.nLeft = LEFT_WIDTH(isLandscape);
    rText.nRight = self.frame.size.width;
    rText.nTop = nVolExpandIndexTop-TITLE_HEIGHT;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    NSString *pStr;
    float fontSize = 10.0;
    UIFont *pFont = [UIFont systemFontOfSize:fontSize];
    
    pStr = [NSString stringWithFormat:@"分时BBD:%@",  VolSumShow(pMinIndex->BBD.bbd[nPosT])];
    CGSize charSize = [pStr sizeWithFont:pFont];
    DrawTools_DrawNSFText(g, &rText, (__bridge void *)(pStr), 0xFFFF00, AGIN_LEFT,fontSize);
}

//绘指标
- (void)drawIndex:(CGContextRef)g withIndex:(int)n withPos:(int)nIndex
{
    switch (n) {
        case MIN_SHOW_INDEX_VOLUME:
            [self drawVolume:g];
            break;
        case MIN_SHOW_INDEX_BUY_SELL_STRENGTH:
            [self drawBuySellStrength:g withPos:nIndex];
            break;
        case MIN_SHOW_INDEX_LEVE2_DDX:
            [self drawLeve2DDX:g];
            break;
        case MIN_SHOW_INDEX_LEVE2_FUND_FLOW:
            [self drawLeve2FundFlow:g];
            break;
        case MIN_SHOW_INDEX_LEVE2_BBD:
            [self drawLeve2BBD:g];
            break;
    }
}

//绘价格刻度
- (void)drawScalesPrice:(CGContextRef)g
{
    GUI_RECT rText;
    int y;
    
    rText.nLeft = 10;
    rText.nRight = rText.nLeft+LEFT_GAP_WIDTH-10;
    
    char sTemp[64];
    char *sFormat;
    char sFormat2[]="%.2f";
    char sFormat3[]="%.3f";
    if (pMinRes->codeinfo.decNum==0x03)
    {
        sFormat = sFormat3;
    }
    else
    {
        sFormat = sFormat2;
    }
    
    //绘最大价刻度
    rText.nTop = nPriceTop-9;
    rText.nBottom = nPriceTop+16;
    sprintf(sTemp, sFormat, fScalesPrice[0]);
    switch (nMode) {
        case MIN_SHOW_MODE_MINI:
            DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[0], pMinRes->fPre)*/[self getMinColor:fScalesPrice[0] with:pMinRes->fPre], AGIN_LEFT);
            break;
        default:
            if (isLandscape) {
                rText.nTop = 5;
                DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[0], pMinRes->fPre)*/[self getMinColor:fScalesPrice[0] with:pMinRes->fPre], AGIN_LEFT);
            }else{
                rText.nLeft = RIGHT_WIDTH(isLandscape) + 5;
                rText.nTop = 5;
                DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[0], pMinRes->fPre)*/[self getMinColor:fScalesPrice[0] with:pMinRes->fPre], AGIN_LEFT);
            }
            break;
    }
    //绘中间价刻度
    if (nMode==MIN_SHOW_MODE_MINI)
    {
        for (int i=1; i<MIN_PRICE_SCALES_NUM-1; i++) {
            y = nPriceTop+nPriceHeight*i/(MIN_PRICE_SCALES_NUM-1);
            rText.nTop = y-10;
            rText.nBottom = y+10;
            sprintf(sTemp, sFormat, fScalesPrice[i]);
            DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[i] with:pMinRes->fPre], AGIN_LEFT);
        }
    }
    else
    {
        for (int i=1; i<MIN_PRICE_SCALES_NUM-1; i++) {
            y = nPriceTop+nPriceHeight*i/(MIN_PRICE_SCALES_NUM-1);
            rText.nTop = y-10;
            rText.nBottom = y+10;
            sprintf(sTemp, sFormat, fScalesPrice[i]);
            if (i == 2) {
                if (isLandscape) {
                    DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[i] with:pMinRes->fPre], AGIN_LEFT);
                }
            }
        }
    }
    //绘最小价刻度
    rText.nTop = nPriceTop+nPriceHeight-16;
    rText.nBottom = nPriceTop+nPriceHeight;
    sprintf(sTemp, sFormat, fScalesPrice[MIN_PRICE_SCALES_NUM-1]);
    if (isLandscape) {
        DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[MIN_PRICE_SCALES_NUM-1], pMinRes->fPre)*/[self getMinColor:fScalesPrice[MIN_PRICE_SCALES_NUM-1] with:pMinRes->fPre], AGIN_LEFT);
    }else{
        rText.nBottom = nPriceTop+nPriceHeight;
        rText.nTop = rText.nBottom - 16;
        DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[MIN_PRICE_SCALES_NUM-1], pMinRes->fPre)*/[self getMinColor:fScalesPrice[MIN_PRICE_SCALES_NUM-1] with:pMinRes->fPre], AGIN_LEFT);
    }
}

//绘幅度刻度
- (void)drawScalesRange:(CGContextRef)g
{
    GUI_RECT rText;
    int y;
    
    rText.nLeft = self.frame.size.width - LEFT_GAP_WIDTH;
    rText.nRight = self.frame.size.width-10;
    
    char sTemp[64];
    char *sFormat;
    char sFormat2[]="%.2f%s";
    char sFormat3[]="%.3f%s";
    if (pMinRes->codeinfo.decNum==0x03)
    {
        sFormat = sFormat3;
    }
    else
    {
        sFormat = sFormat2;
    }
    
    //绘最大价刻度
    rText.nTop = nPriceTop-10;
    rText.nBottom = nPriceTop+16;
    sprintf(sTemp, sFormat, fScalesRange[0],"%");
    switch (nMode) {
        case MIN_SHOW_MODE_MINI:
            //DrawTools_DrawText(g, &rText, sTemp, getColorRGB24(fScalesPrice[0], pMinRes->fPre), AGIN_RIGHT);
            break;
        default:
            if (isLandscape) {
                rText.nTop = 5;
                DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[0] with:pMinRes->fPre], AGIN_RIGHT);
            }else{
                rText.nLeft = self.frame.size.width - RIGHT_WIDTH(isLandscape) - 80;
                rText.nRight = self.frame.size.width - RIGHT_WIDTH(isLandscape) - 5;
                rText.nTop = 5;
                DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[0] with:pMinRes->fPre], AGIN_RIGHT);
            }
            break;
    }
    //绘中间价刻度
    if (nMode==MIN_SHOW_MODE_MINI)
    {
        for (int i=1; i<MIN_PRICE_SCALES_NUM-1; i++) {
            y = nPriceTop+nPriceHeight*i/(MIN_PRICE_SCALES_NUM-1);
            rText.nTop = y-10;
            rText.nBottom = y+10;
            sprintf(sTemp, sFormat, fScalesRange[i],"%");
            DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[i] with:pMinRes->fPre], AGIN_RIGHT);
        }
    }
    else
    {
        for (int i=1; i<MIN_PRICE_SCALES_NUM-1; i++) {
            y = nPriceTop+nPriceHeight*i/(MIN_PRICE_SCALES_NUM-1);
            rText.nTop = y-10;
            rText.nBottom = y+10;
            sprintf(sTemp, sFormat, absf(fScalesRange[i]),"%");
            if (i == 2) {
                if (isLandscape) {
                    DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[i] with:pMinRes->fPre], AGIN_RIGHT);
                }
            }
        }
    }
    //绘最小价刻度
    rText.nTop = nPriceTop+nPriceHeight-16;
    rText.nBottom = nPriceTop+nPriceHeight;
    sprintf(sTemp, sFormat, fScalesRange[MIN_PRICE_SCALES_NUM-1],"%");
    if (isLandscape) {
        DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[MIN_PRICE_SCALES_NUM-1] with:pMinRes->fPre], AGIN_RIGHT);
    }else{
        rText.nLeft = self.frame.size.width - RIGHT_WIDTH(isLandscape) - 80;
        rText.nRight = self.frame.size.width - RIGHT_WIDTH(isLandscape) - 5;
        rText.nBottom = nPriceTop+nPriceHeight;
        rText.nTop = rText.nBottom - 16;
        DrawTools_DrawText(g, &rText, sTemp, /*getColorRGB24(fScalesPrice[i], pMinRes->fPre)*/[self getMinColor:fScalesPrice[MIN_PRICE_SCALES_NUM-1] with:pMinRes->fPre], AGIN_RIGHT);
    }
}

- (void)drawScalesTime:(CGContextRef)g
             withIndex:(int)nIndex
             withWidth:(int)width
       withFirstCloseX:(int)nFirstCloseX
{
    char sTemp[64];
    GUI_RECT rText;
    GUI_RECT rFirstCloseText;
    
    //点信息
    GUI_RECT rPText;
    rPText.nLeft = LEFT_WIDTH(isLandscape);
    rPText.nTop = 0;
    rPText.nRight = rPText.nLeft+30;
    rPText.nBottom = rPText.nTop+TITLE_HEIGHT;
    
    
    //计算时间
    if (TOP_SPACING_PRICE>=TITLE_HEIGHT)
    {
        QUOTELV_TRADING_HOURS_ITEM *pItem = [self getTradingHours];
        
        int nBase;	//开市基础时间
        int nPosCount;	//第一次开盘时间分钟
        
        int nTIndex;
        if (pItem)
        {
            if (pItem) {
                nPosCount = CalcTimeDiffer(pItem->firstOpen, pItem->firstClose);
            }
            
            if (nIndex<=nPosCount) {
                nBase = pItem->firstOpen;
                nTIndex = nIndex;
            }
            else
            {
                nBase = pItem->secodeOpen;
                nTIndex = nIndex-nPosCount-1;
            }
        }
        else
        {
            if(pMinRes->codeinfo.style==STOCK_STYLE_FUTURES_STOCK)
            {
                nBase = 9*60+15;
                nPosCount = 135;
            }
            else
            {
                nBase = 9*60+30;
                nPosCount = 120;
            }
            
            if (nIndex<=nPosCount) {
                nTIndex = nIndex;
            }
            else
            {
                nTIndex = nIndex-nPosCount-1;
            }
        }
        
        
        
        //第一次
        int nHour   = nBase/100;
        int nMin    = nBase%100;
        
        nHour += nTIndex / 60 ;
        nMin  += (nTIndex% 60);
        if (nMin >= 60)
        {
            nHour ++;
            nMin -= 60;
        }
        sprintf(sTemp,"%02d:%02d",  nHour,nMin );
        
        //时间
        DrawTools_DrawNSText(g, &rPText, @"时间:", sal_color, AGIN_CENTER);
        rPText.nLeft = rPText.nRight;
        rPText.nRight = rPText.nLeft+40;
        DrawTools_DrawText(g, &rPText, sTemp, sal_color, AGIN_CENTER);
        
        //现价
        rPText.nLeft = rPText.nRight+20;
        rPText.nRight = rPText.nLeft+40;
        DrawTools_DrawNSText(g, &rPText, @"现价:", sal_color, AGIN_CENTER);
        rPText.nLeft = rPText.nRight;
        rPText.nRight = rPText.nLeft+60;
        DrawTools_DrawNSText(g, &rPText, (__bridge void *)(PriShow(pMinRes->minData[nIndex].fPri)), getColorRGB24(pMinRes->minData[nIndex].fPri, pMinRes->fPre), AGIN_LEFT);
        
        //均价
        rPText.nLeft = rPText.nRight+20;
        rPText.nRight = rPText.nLeft+40;
        DrawTools_DrawNSText(g, &rPText, @"均价:", sal_color, AGIN_CENTER);
        rPText.nLeft = rPText.nRight;
        rPText.nRight = rPText.nLeft+60;
        DrawTools_DrawNSText(g, &rPText, (__bridge void *)(PriShow(pMinRes->minData[nIndex].fAvgPrice)), getColorRGB24(pMinRes->minData[nIndex].fAvgPrice, pMinRes->fPre), AGIN_LEFT);
        
        //幅度
        rPText.nLeft = rPText.nRight+20;
        rPText.nRight = rPText.nLeft+40;
        DrawTools_DrawNSText(g, &rPText, @"幅度:", sal_color, AGIN_CENTER);
        rPText.nLeft = rPText.nRight;
        rPText.nRight = rPText.nLeft+60;
        DrawTools_DrawNSText(g, &rPText, (__bridge void *)(DRShow(pMinRes->minData[nIndex].fPri, pMinRes->fPre)), getColorRGB24(pMinRes->minData[nIndex].fPri, pMinRes->fPre), AGIN_LEFT);
    }
    
    
    //绘时间
    rText.nLeft = LEFT_WIDTH(isLandscape);
    rText.nRight = rText.nLeft+width;
    rText.nTop = nVolExpandIndexTop+nVolExpandIndexHeight+2;//;
    rText.nBottom = rText.nTop+TITLE_HEIGHT;
    
    if (nMode==MIN_SHOW_MODE_MINI || nMode == MIN_SHOW_MODE_NORMAL)
    {
//        rText.nTop = nPriceHeight + nPriceTop + 2;
        rText.nTop = nVolHeight + nVolTop + 2;
        rText.nBottom = rText.nTop+TITLE_HEIGHT;
    }
    
    //第一次闭市时间
    rFirstCloseText = rText;
    rFirstCloseText.nLeft = nFirstCloseX-50;
    rFirstCloseText.nRight = rFirstCloseText.nLeft+100;
    
    if(pItem)
    {
        FormatHoursMinute(sTemp, pItem->firstOpen);
        DrawTools_DrawText(g, &rText, sTemp, /*0x00AAFF*/equalColor, AGIN_LEFT);
        FormatHoursMinute(sTemp, pItem->firstClose);
        sprintf(sTemp,"%s%s",sTemp,"/");
        char buf[8]={0};
        FormatHoursMinute(buf, pItem->secodeOpen);
        sprintf(sTemp,"%s%s",sTemp,buf);
        DrawTools_DrawText(g, &rFirstCloseText, sTemp, /*0x00AAFF*/equalColor, AGIN_CENTER);
        FormatHoursMinute(sTemp, pItem->secodeClose);
        DrawTools_DrawText(g, &rText, sTemp, /*0x00AAFF*/equalColor, AGIN_RIGHT);
    }
}

-(void)layoutVol{
  CGRect rect = CGRectMake(LEFT_WIDTH(isLandscape), nPriceHeight + nPriceTop + 2, 40, TITLE_HEIGHT);
  mVol.frame = rect;
  rect = CGRectMake(LEFT_WIDTH(isLandscape)+40, nPriceHeight + nPriceTop + 2, self.frame.size.width/2-LEFT_WIDTH(isLandscape)-40, TITLE_HEIGHT);
  mVolValue.frame = rect;
  
  rect = CGRectMake(LEFT_WIDTH(isLandscape)+self.frame.size.width/2, nPriceHeight + nPriceTop + 2, 30, TITLE_HEIGHT);
  mHand.frame = rect;
  rect = CGRectMake(LEFT_WIDTH(isLandscape)+self.frame.size.width/2+30, nPriceHeight + nPriceTop + 2, self.frame.size.width/2-LEFT_WIDTH(isLandscape)-30, TITLE_HEIGHT);
  mHandValue.frame = rect;
  
  mVol.hidden = mVolValue.hidden = mHand.hidden = mHandValue.hidden = NO;
}

- (void)drawMine:(CGContextRef)g
{
    for (int i=0; i<nMineCount; i++) {
        GUI_RECT rr;
        rr.nLeft = pMine[i].x;
        rr.nTop = pMine[i].y+nMineTop;
        rr.nRight = rr.nLeft+20;
        rr.nBottom = rr.nTop+40;
        DrawTools_DrawNSFText(g, &rr, @"*", 0x333333, AGIN_CENTER, 20);
    }
}

- (void)drawMul:(CGContextRef)g withWidth:(int)w
{//画十字线
    
    if (!bMul) {
        mLeftView.hidden = YES;
        mRightView.hidden = YES;
        mBottomView.hidden = YES;
        return;
    }
    
    //垂直线
    int xx = m_pf_point_x[nPos];//w*1.0/nMaxPosCount*nPos+LEFT_WIDTH;
    DrawTools_DrawLine(g, xx, nPriceTop, xx, nPriceTop+nPriceHeight+2, tenLineColor, 0);
    DrawTools_DrawLine(g, xx, nVolTop, xx, nVolTop+nVolHeight+2, tenLineColor, 0);
    DrawTools_DrawLine(g, xx, nVolExpandIndexTop, xx, nVolExpandIndexTop+nVolExpandIndexHeight+2, tenLineColor, 0);
    //水平线
    if (ty > 0 && ty < nVolTop - TITLE_HEIGHT) {
        DrawTools_DrawLine(g, LEFT_WIDTH(isLandscape), ty, self.frame.size.width - RIGHT_WIDTH(isLandscape), ty, tenLineColor, 0);
        mLeftView.hidden = NO;
        mRightView.hidden = NO;
    }else {
        mLeftView.hidden = YES;
        mRightView.hidden = YES;
    }
    float x,y;
    x = 0;
    y = ty - mLeftView.frame.size.height / 2;
    mLeftView.frame = CGRectMake(x, y, mLeftView.frame.size.width, mLeftView.frame.size.height);
    float pm = pMinRes->minData[nPos].fPri;
    
    float pm1 = (pMinRes->minData[nPos].fPri - pMinRes->fPre)*100 /pMinRes->fPre;
    
//    x = self.frame.size.width - RIGHT_WIDTH(isLandscape);
    x = self.frame.size.width - mRightView.frame.size.width;
    mRightView.frame = CGRectMake(x, y, mRightView.frame.size.width, mRightView.frame.size.height);
    //[mRight setText:[NSString stringWithFormat:@"%.2f%%",pm]];
    
    if (pMinRes->codeinfo.decNum==0x03)
    {
        [mLeft setText:[NSString stringWithFormat:@"%.3f",pm]];
        [mRight setText:[NSString stringWithFormat:@"%.3f%%",pm1]];
    }
    else
    {
        [mLeft setText:[NSString stringWithFormat:@"%.2f",pm]];
        [mRight setText:[NSString stringWithFormat:@"%.2f%%",pm1]];
    }
    //
    x = xx - mBottomView.frame.size.width / 2;
    y = nPriceTop + nPriceHeight + 1;
    mBottomView.frame = CGRectMake(x,y,mBottomView.frame.size.width,mBottomView.frame.size.height);
    [mBottom setText:[self clacTime]];
    //
    mBottomView.hidden = NO;
    //
}

-(NSString*)clacTime
{
    int nIndex = nPos;
    char sTemp[64];
    GUI_RECT rText;
    //点信息
    GUI_RECT rPText;
    rPText.nLeft = LEFT_WIDTH(isLandscape);
    rPText.nTop = 0;
    rPText.nRight = rPText.nLeft+30;
    rPText.nBottom = rPText.nTop+TITLE_HEIGHT;
    
    //计算时间
    QUOTELV_TRADING_HOURS_ITEM *pItem = [self getTradingHours];
    
    int nBase;	//开市基础时间
    int nPosCount;	//第一次开盘时间分钟
    
    int nTIndex;
    if (pItem)
    {
        if (pItem) {
            nPosCount = CalcTimeDiffer(pItem->firstOpen, pItem->firstClose);
        }
        
        if (nIndex<=nPosCount) {
            nBase = pItem->firstOpen;
            nTIndex = nIndex;
        }
        else
        {
            nBase = pItem->secodeOpen;
            nTIndex = nIndex-nPosCount-1;
        }
    }
    else
    {
        if(pMinRes->codeinfo.style==STOCK_STYLE_FUTURES_STOCK)
        {
            nBase = 9*60+15;
            nPosCount = 135;
        }
        else
        {
            nBase = 9*60+30;
            nPosCount = 120;
        }
        
        if (nIndex<=nPosCount) {
            nTIndex = nIndex;
        }
        else
        {
            nTIndex = nIndex-nPosCount-1;
        }
    }
    
    
    
    //第一次
    int nHour   = nBase/100;
    int nMin    = nBase%100;
    
    nHour += nTIndex / 60 ;
    nMin  += (nTIndex% 60);
    if (nMin >= 60)
    {
        nHour ++;
        nMin -= 60;
    }
    sprintf(sTemp,"%02d:%02d",  nHour,nMin );
    return [NSString stringWithUTF8String:sTemp];
}

//lisz add 20110916 end
- (void)drawRect:(CGRect)rect {
    if (!pMinRes) {
        return;
    }
    // Drawing code
    CGContextRef g = UIGraphicsGetCurrentContext();
  
    if(g == 0x0){
      return;
    }
  
    int nFirstCloseX;
    
    [self calcRect];
    
    int w;
    w = self.frame.size.width-LEFT_WIDTH(isLandscape);
    
    GUI_RECT r;
    r.nLeft = LEFT_WIDTH(isLandscape);
    r.nRight = r.nLeft+w;
    r.nTop = nPriceTop;
    if (nMode==MIN_SHOW_MODE_MINI) {
        r.nBottom  = r.nTop+nPriceHeight+2;
    }
    else if(nMode==MIN_SHOW_MODE_EXPAND_INDEX){
        r.nBottom  = nVolExpandIndexTop+nVolExpandIndexHeight+2;
        w -= RIGHT_WIDTH(isLandscape);
        r.nRight = r.nLeft+w;
    }
    else {
        r.nBottom  = nVolTop+nVolHeight+2;//价格和量相连
        w -= RIGHT_WIDTH(isLandscape);
        r.nRight = r.nLeft+w;
    }
    
    if (isSeparatePriceLineAndVol) {
        //绘边框
        DrawTools_DrawLine(g, r.nLeft, r.nTop, r.nRight, r.nTop, frameColor, 0);
        //绘制价格左右两侧边框
        r.nBottom = nPriceTop + nPriceHeight + 1;
        DrawTools_DrawLine(g, r.nLeft, nPriceTop, r.nLeft, r.nBottom, frameColor, 0);
        DrawTools_DrawLine(g, r.nLeft+w-1, nPriceTop, r.nLeft+w-1, r.nBottom, frameColor, 0);
        //绘制量左右两侧边框
        r.nBottom = nVolTop + nVolHeight + 1;
        DrawTools_DrawLine(g, r.nLeft, nVolTop, r.nLeft, r.nBottom, frameColor, 0);
        DrawTools_DrawLine(g, r.nLeft+w-1, nVolTop, r.nLeft+w-1, r.nBottom, frameColor, 0);
    }else{
        //绘边框
        DrawTools_DrawLine(g, r.nLeft, r.nTop, r.nRight, r.nTop, frameColor, 0);
        DrawTools_DrawLine(g, r.nLeft, nPriceTop, r.nLeft, r.nBottom, frameColor, 0);
        DrawTools_DrawLine(g, r.nLeft+w-1, nPriceTop, r.nLeft+w-1, r.nBottom, frameColor, 0);
    }
    
    
    
    //第一次收盘时间x
    nFirstCloseX = r.nLeft+w/2 - 1;
    
    //	switch (nMode) {
    //		case MIN_SHOW_MODE_MINI:
    //			nColor = scalesLineColor;
    //			break;
    //		default:
    //			nColor = scalesLineColor;
    //			break;
    //	}
    
    int y;
    
    //绘价水平线分隔
    if (nMode==MIN_SHOW_MODE_MINI)
    {
        //DrawTools_DrawLine(g, r.nLeft, nPriceTop+(nPriceHeight+2)/2, r.nRight, nPriceTop+(nPriceHeight+2)/2, nColor, 0);
        for (int i=1; i<MIN_PRICE_SCALES_NUM-1; i++) {
            y = nPriceTop+(nPriceHeight+2)*i/(MIN_PRICE_SCALES_NUM-1);
            if (i!=MIN_PRICE_SCALES_NUM/2) {
                DrawTools_DrawLine(g, r.nLeft, y, r.nRight, y, scalesLineColor, PEN_STYLE_DOTLINE);
            }
            else {
                DrawTools_DrawLine(g, r.nLeft, y, r.nRight, y, scalesLineColor, /*PEN_STYLE_SOLIDLINE*/PEN_STYLE_DOTLINE);
            }
        }
    }
    else
    {
        for (int i=1; i<MIN_PRICE_SCALES_NUM-1; i++) {
            y = nPriceTop+(nPriceHeight)*i/(MIN_PRICE_SCALES_NUM-1);
            if (i!=MIN_PRICE_SCALES_NUM/2) {
                //				DrawTools_DrawLine(g, r.nLeft, y, r.nRight, y, scalesLineColor, PEN_STYLE_DOTLINE);
            }
            else {
                DrawTools_DrawLine(g, r.nLeft, y, r.nRight, y, scalesLineColor, /*PEN_STYLE_SOLIDLINE*/PEN_STYLE_DOTLINE);
            }
        }
    }
    
    
    
    switch (nMode) {
        case MIN_SHOW_MODE_MINI:
        {
            if (pMinRes && pItem) {
                int nFirstPointCount;
                int nSecondPointCount;
                int fFirstWidth;
                int fSecondWidth;
                int nFirstPos;
                int i,x;
                float *a_pf_point_x;
                int w = self.frame.size.width;
                
                nFirstPointCount = CalcTimeDiffer(pItem->firstOpen, pItem->firstClose)+1;
                nSecondPointCount = CalcTimeDiffer(pItem->secodeOpen, pItem->secodeClose)+1;
                fFirstWidth = (w - LEFT_WIDTH(isLandscape)  - 2)*1.0/(nFirstPointCount+nSecondPointCount)*nFirstPointCount;
                fSecondWidth = (w - LEFT_WIDTH(isLandscape)  - 2)*1.0/(nFirstPointCount+nSecondPointCount)*nSecondPointCount;
                nFirstPos = pItem->firstOpen%100;
                if (nFirstPos<30) {
                    nFirstPos = 30-nFirstPos;
                } else if (nFirstPos<60) {
                    nFirstPos = 60-nFirstPos;
                }
                a_pf_point_x = Tools_Malloc(sizeof(float)*nMaxPosCount);
                for (i=0; i<(nFirstPointCount+nSecondPointCount); i++) {
                    if (i<nFirstPointCount) {
                        a_pf_point_x[i] = LEFT_WIDTH(isLandscape) + 1 + (fFirstWidth*(float)i)/(nFirstPointCount-1);
                    } else {
                        a_pf_point_x[i] = LEFT_WIDTH(isLandscape) + 1 + fFirstWidth + (fSecondWidth*(float)(i-nFirstPointCount+1))/(nSecondPointCount);
                    }
                }
                
                for (i=nFirstPos; i<(nFirstPointCount+nSecondPointCount)-1;) {
                    x = a_pf_point_x[i];
                    if (i==nFirstPointCount-1) {//上午收盘
                        nFirstCloseX = x;
                        DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight+2, scalesLineColor, PEN_STYLE_DOTLINE);
                        if (nMode==MIN_SHOW_MODE_EXPAND_INDEX) {
                            DrawTools_DrawLine(g, x, nVolExpandIndexTop, x, nVolExpandIndexTop+nVolExpandIndexHeight+2, scalesLineColor, PEN_STYLE_DOTLINE);
                        }
                    }
                    i+=30;
                }
                
                Tools_Free(&a_pf_point_x);
            } else {
                //量垂直中线
                DrawTools_DrawLine(g, r.nLeft+w/2, nPriceTop, r.nLeft+w/2, nPriceHeight, scalesLineColor, PEN_STYLE_DOTLINE);
            }
        }
            break;
        case MIN_SHOW_MODE_EXPAND_INDEX:
            //买卖力道
            //      //量垂直中线
            //      DrawTools_DrawLine(g, r.nLeft+w/2, nVolExpandIndexTop, r.nLeft+w/2, nVolExpandIndexTop+nVolExpandIndexHeight+2, 0x595959, PEN_STYLE_DOTLINE);
            
            //量水平顶边框
            DrawTools_DrawLine(g, r.nLeft, nVolExpandIndexTop, r.nRight, nVolExpandIndexTop, frameColor, 0);
            //量水平中线
            int nVT = nVolExpandIndexTop+(nVolExpandIndexHeight)/2+1;
            DrawTools_DrawLine(g, r.nLeft, nVT, r.nLeft+w, nVT, scalesLineColor, PEN_STYLE_DOTLINE);
            //量底线
            DrawTools_DrawLine(g, r.nLeft, nVolExpandIndexTop+nVolExpandIndexHeight+2, r.nLeft+w, nVolExpandIndexTop+nVolExpandIndexHeight+2, frameColor, 0);
        case MIN_SHOW_MODE_NORMAL:
            //价线底边框
            DrawTools_DrawLine(g, r.nLeft, nPriceTop+nPriceHeight+1, r.nRight, nPriceTop+nPriceHeight+1, frameColor, 0);
            
            if (pMinRes && pItem) {//根据股票类型绘垂直线
                int nFirstPointCount;
                int nSecondPointCount;
                int fFirstWidth;
                int fSecondWidth;
                int nFirstPos;
                int i,x;
                float *a_pf_point_x;
                int w = self.frame.size.width;
                //        int nHouse;//iphone平台修改为每一时间绘间隔
                
                nFirstPointCount = CalcTimeDiffer(pItem->firstOpen, pItem->firstClose)+1;
                nSecondPointCount = CalcTimeDiffer(pItem->secodeOpen, pItem->secodeClose)+1;
                fFirstWidth = (w - LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape) - 2)*1.0/(nFirstPointCount+nSecondPointCount)*nFirstPointCount;
                fSecondWidth = (w - LEFT_WIDTH(isLandscape) - RIGHT_WIDTH(isLandscape) - 2)*1.0/(nFirstPointCount+nSecondPointCount)*nSecondPointCount;
                nFirstPos = pItem->firstOpen%100;
                if (nFirstPos<30) {
                    nFirstPos = 30-nFirstPos;
                } else if (nFirstPos<60) {
                    nFirstPos = 60-nFirstPos;
                }
                a_pf_point_x = Tools_Malloc(sizeof(float)*nMaxPosCount);
                for (i=0; i<(nFirstPointCount+nSecondPointCount); i++) {
                    if (i<nFirstPointCount) {
                        a_pf_point_x[i] = LEFT_WIDTH(isLandscape) + 1 + (fFirstWidth*(float)i)/(nFirstPointCount-1);
                    } else {
                        a_pf_point_x[i] = LEFT_WIDTH(isLandscape) + 1 + fFirstWidth + (fSecondWidth*(float)(i-nFirstPointCount+1))/(nSecondPointCount);
                    }
                }
                //        nHouse = 0;
                for (i=nFirstPos; i<(nFirstPointCount+nSecondPointCount)-1;) {
                    x = a_pf_point_x[i];
                    //          if (i<30) {//iphone平台修改为每一时间绘间隔，但第一次整点需要直接绘出
                    //            nHouse=1;
                    //          }
                    if (i==nFirstPointCount-1) {//上午收盘
                        nFirstCloseX = x;
                        DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight+2, scalesLineColor, PEN_STYLE_DOTLINE);
                        DrawTools_DrawLine(g, x, nVolTop, x, nVolTop+nVolHeight+2, scalesLineColor, PEN_STYLE_DOTLINE);
                        if (nMode==MIN_SHOW_MODE_EXPAND_INDEX) {
                            DrawTools_DrawLine(g, x, nVolExpandIndexTop, x, nVolExpandIndexTop+nVolExpandIndexHeight+2, scalesLineColor, PEN_STYLE_DOTLINE);
                        }
                    }/* else if (i<nFirstPointCount && nHouse%2!=0) {//上午盘
                      DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight+2, nColor, PEN_STYLE_DOTLINE);
                      DrawTools_DrawLine(g, x, nVolTop, x, nVolTop+nVolHeight+2, nColor, PEN_STYLE_DOTLINE);            
                      } else if(nHouse%2!=0){
                      x = m_pf_point_x[i+1];
                      DrawTools_DrawLine(g, x, nPriceTop, x, nPriceTop+nPriceHeight+2, nColor, PEN_STYLE_DOTLINE);
                      DrawTools_DrawLine(g, x, nVolTop, x, nVolTop+nVolHeight+2, nColor, PEN_STYLE_DOTLINE);
                      }*/
                    i+=30;
                    //          if (i<60) {
                    //            nHouse=0;
                    //          } else {
                    //            nHouse++;
                    //          }
                }
                
                Tools_Free(&a_pf_point_x);
            } else {//无股票数据时画一个默认垂直线
                if (nMode==MIN_SHOW_MODE_EXPAND_INDEX) {
                    DrawTools_DrawLine(g, r.nLeft+w/2 - 1, nVolExpandIndexTop, r.nLeft+w/2 - 1, nVolExpandIndexTop+nVolExpandIndexHeight+2, scalesLineColor, 0);
                }
                //价垂直分隔线
                for (int i=1; i<8; i++) {
                    ///modified by Gavin 120327
                    ///修改刻度中线不对齐的问题
                    /*if (i!=8/2) {
                     DrawTools_DrawLine(g, r.nLeft+w*i/8, nPriceTop, r.nLeft+w*i/8, nPriceTop+nPriceHeight+2, nColor, PEN_STYLE_DOTLINE);
                     DrawTools_DrawLine(g, r.nLeft+w*i/8, nVolTop, r.nLeft+w*i/8, nVolTop+nVolHeight+2, nColor, PEN_STYLE_DOTLINE);
                     } else {*/
                    if (i==8/2) {
                        DrawTools_DrawLine(g, r.nLeft+w*i/8, nPriceTop, r.nLeft+w*i/8, nPriceTop+nPriceHeight+2, scalesLineColor, PEN_STYLE_SOLIDLINE);
                        DrawTools_DrawLine(g, r.nLeft+w*i/8, nVolTop, r.nLeft+w*i/8, nVolTop+nVolHeight+2, scalesLineColor, 0);;
                    }
                    ///end modify
                }
            }
            
            //量水平顶边框
            DrawTools_DrawLine(g, r.nLeft, nVolTop, r.nRight, nVolTop, frameColor, 0);
            //量水平中线
            DrawTools_DrawLine(g, r.nLeft, nVolTop+(nVolHeight)/2+1, r.nLeft+w, nVolTop+(nVolHeight)/2+1, scalesLineColor, PEN_STYLE_DOTLINE);
            //量底线
            DrawTools_DrawLine(g, r.nLeft, nVolTop+nVolHeight+1, r.nLeft+w, nVolTop+nVolHeight+1, frameColor, 0);
            break;
    }
    
    
    if (pMinRes) {
        switch (nMode) {
            case MIN_SHOW_MODE_MINI:
            {
                //填充价变色区域
                DrawTools_DrawBezierPath(g, pLineCur, pMinRes->nTotalCount, nPriceHeight-1, bezierColor, bezierColor);
                //描价格边线
                DrawTools_DrawPath(g, pLineCur, pMinRes->nTotalCount, pathColor);
                
                //不显示十字线时绘股票名称
                if (bMul==NO) {
                    GUI_RECT rPrice;
                    rPrice = r;
                    rPrice.nBottom = rPrice.nTop+nPriceHeight;
                    //DrawTools_DrawFAText(g, &rPrice, pMinRes->codeinfo.name, 0x686868, AGIN_CENTER, 40, 0.5);
                }
            }
                break;
            case MIN_SHOW_MODE_NORMAL:
            case MIN_SHOW_MODE_EXPAND_INDEX:
            {
                //填充价变色区域
                DrawTools_DrawBezierPath(g, pLineCur, pMinRes->nTotalCount, nPriceHeight, bezierColor, bezierColor);
                //描价格边线
                DrawTools_DrawPath(g, pLineCur, pMinRes->nTotalCount, pathColor);
                [self drawCircleWithContext:g];
              
                if (pLineAvg->y>0) {
                    //如果均价不为0绘均价线
                    DrawTools_DrawPath(g, pLineAvg, pMinRes->nTotalCount, avgColor);
                }
                /*
                 //不显示十字线时绘股票名称
                 if (bMul==NO) {
                 GUI_RECT rPrice;
                 rPrice = r;
                 rPrice.nBottom = rPrice.nTop+nPriceHeight;
                 DrawTools_DrawFText(g, &rPrice, pMinRes->codeinfo.name, 0xAAAAAA, AGIN_CENTER, 40);
                 }
                 
                 //draw rdp
                 int nRdpY;
                 nRdpY = nMineTop+nPriceHeight/2;
                 for (int i=0; i<nRdpUp; i++) {
                 DrawTools_DrawLine(g, pRdpUp[i].x, pRdpUp[i].y, pRdpUp[i].x, nRdpY, 0xFF0000, 0);
                 }
                 for (int i=0; i<nRdpDown; i++) {
                 DrawTools_DrawLine(g, pRdpDown[i].x, pRdpDown[i].y, pRdpDown[i].x, nRdpY, 0x22FF22, 0);
                 }
                 
                 //价线
                 DrawTools_DrawPath(g, pLineCur, pMinRes->nTotalCount, priceColor);
                 if (pLineAvg->y>0) {
                 //如果均价不为0绘均价线
                 DrawTools_DrawPath(g, pLineAvg, pMinRes->nTotalCount, avgColor);
                 }
                 */
            }
                break;
        }
        
        int nIndex = nPos;
        if (nIndex<0) {
            nIndex = pMinRes->nTotalCount-1;
        }
        
        switch (nMode) {
            case MIN_SHOW_MODE_MINI:
                break;
            case MIN_SHOW_MODE_NORMAL:
            {
                [self drawIndex:g withIndex:nExpandIndex withPos:nIndex];
            }
                break;
            case MIN_SHOW_MODE_EXPAND_INDEX:
            {
                [self drawIndex:g withIndex:MIN_SHOW_INDEX_VOLUME withPos:nIndex];
                [self drawIndex:g withIndex:nExpandIndex withPos:nIndex];
            }
                break;
        }
        
        
        //绘价刻度值
        [self drawScalesPrice:g];
        
        switch (nMode) {
            case MIN_SHOW_MODE_MINI:
                [self drawScalesTime:g
                           withIndex:nIndex
                           withWidth:w
                     withFirstCloseX:nFirstCloseX];
                break;
            default:
            {
                [self drawScalesRange:g];
                [self drawScalesTime:g
                           withIndex:nIndex
                           withWidth:w
                     withFirstCloseX:nFirstCloseX];
                 [self layoutVol];
            }
                break;
        }
        
        
        
        if (pMinInfoRes) {
            [self drawMine:g];
        }
        
        if (bMul) {
            [self drawMul:g withWidth:w];
        }else {
            mLeftView.hidden = YES;
            mRightView.hidden = YES;
            mBottomView.hidden = YES;
        }
        
    }
}

-(void)OnChangeView:(int)n
{
    [self calcData];
    [self calcMineData];
    [self setNeedsDisplay];
}

- (void)OnChangeTheme:(int)nThemeId withPath:(NSString*)path{
  
  if(nThemeId == 1){
    frameColor = 0x3b4050;//0xdddddd
    scalesLineColor = 0x3b4050;//0xdddddd
    [mVerButton setTitleColor:_rgb2uic(0x8c96b4, 1) forState:UIControlStateNormal];
  }else{
    frameColor = 0xdddddd;
    scalesLineColor = 0xdddddd;
    [mVerButton setTitleColor:_rgb2uic(0xf5f5f5, 1) forState:UIControlStateNormal];
  }
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark -
- (void)upToParentWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
}
- (void)downToChildWithObjc:(id)objc withType:(NSInteger)type withParamter:(id)paramter{
    switch (type) {
        case kHZ_cancelLandscapeScreen_Action:
        {
            pLandScapeBtn.hidden = NO;
        }
            break;
            
        default:
            break;
    }
}

@end
